Serializable
, Map<String,Object>
, Bson
A representation of a document as a Map
. All iterators will traverse the elements in insertion order, as with LinkedHashMap
.
Constructors
Creates an empty Document instance.
Create a Document instance initialized with the given key/value pair.
Creates a Document instance initialized with the given map.
Put the given key/value pair into this Document and return this.
void
boolean
boolean
boolean
<T> T
Gets the value of the given key, casting it to the given Class<T>
.
<T> T
Gets the value of the given key, casting it to Class<T>
or returning the default value if null.
Gets the value of the given key as a Boolean.
boolean
Gets the value of the given key as a primitive boolean.
Gets the value of the given key as a Date.
Gets the value of the given key as a Double.
<T> T
Gets the value in an embedded document, casting it to the given Class<T>
.
<T> T
Gets the value in an embedded document, casting it to the given Class<T>
or returning the default value if null.
Gets the value of the given key as an Integer.
int
Gets the value of the given key as a primitive int.
Gets the list value of the given key, casting the list elements to the given Class<T>
.
Gets the list value of the given key, casting the list elements to Class<T>
or returning the default list value if null.
Gets the value of the given key as a Long.
Gets the value of the given key as an ObjectId.
Gets the value of the given key as a String.
int
boolean
Parses a string in MongoDB Extended JSON format to a Document
Parses a string in MongoDB Extended JSON format to a Document
void
int
Render into a BsonDocument.
Gets a JSON representation of this document
Gets a JSON representation of this document
Gets a JSON representation of this document
Methods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public Document()
Creates an empty Document instance.
Create a Document instance initialized with the given key/value pair.
key
- key
value
- value
Creates a Document instance initialized with the given map.
map
- initial map
Parses a string in MongoDB Extended JSON format to a Document
json
- the JSON string
Document
object
Parses a string in MongoDB Extended JSON format to a Document
json
- the JSON string
decoder
- the Decoder
to use to parse the JSON string into a Document
Document
object
Bson
Render into a BsonDocument.
toBsonDocument
in interface Bson
C
- the type of the document class
documentClass
- the document class in scope for the collection. This parameter may be ignored, but it may be used to alter the structure of the returned BsonDocument
based on some knowledge of the document class.
codecRegistry
- the codec registry. This parameter may be ignored, but it may be used to look up Codec
instances for the document class or any other related class.
Put the given key/value pair into this Document and return this. Useful for chaining puts in a single expression, e.g.
doc.append("a", 1).append("b", 2)}
key
- key
value
- value
Gets the value of the given key, casting it to the given Class<T>
. This is useful to avoid having casts in client code, though the effect is the same. So to get the value of a key that is of type String, you would write String name = doc.get("name", String.class)
instead of String name = (String) doc.get("x")
.
T
- the type of the class
key
- the key
clazz
- the non-null class to cast the value to
ClassCastException
- if the value of the given key is not of type T
Gets the value of the given key, casting it to Class<T>
or returning the default value if null. This is useful to avoid having casts in client code, though the effect is the same.
T
- the type of the class
key
- the key
defaultValue
- what to return if the value is null
ClassCastException
- if the value of the given key is not of type T
Gets the value in an embedded document, casting it to the given
Class<T>
. The list of keys represents a path to the embedded value, drilling down into an embedded document for each key. This is useful to avoid having casts in client code, though the effect is the same.
The generic type of the keys list is ?
to be consistent with the corresponding get
methods, but in practice the actual type of the argument should be List<String>
. So to get the embedded value of a key list that is of type String, you would write String name = doc.getEmbedded(List.of("employee", "manager", "name"), String.class)
instead of String name = (String) doc.get("employee", Document.class).get("manager", Document.class).get("name")
.
T
- the type of the class
keys
- the list of keys
clazz
- the non-null class to cast the value to
ClassCastException
- if the value of the given embedded key is not of type T
Gets the value in an embedded document, casting it to the given
Class<T>
or returning the default value if null. The list of keys represents a path to the embedded value, drilling down into an embedded document for each key. This is useful to avoid having casts in client code, though the effect is the same.
The generic type of the keys list is ?
to be consistent with the corresponding get
methods, but in practice the actual type of the argument should be List<String>
. So to get the embedded value of a key list that is of type String, you would write String name = doc.getEmbedded(List.of("employee", "manager", "name"), "John Smith")
instead of String name = doc.get("employee", Document.class).get("manager", Document.class).get("name", "John Smith")
.
T
- the type of the class
keys
- the list of keys
defaultValue
- what to return if the value is null
ClassCastException
- if the value of the given key is not of type T
Gets the value of the given key as an Integer.
key
- the key
ClassCastException
- if the value is not an integer
Gets the value of the given key as a primitive int.
key
- the key
defaultValue
- what to return if the value is null
ClassCastException
- if the value is not an integer
Gets the value of the given key as a Long.
key
- the key
ClassCastException
- if the value is not an long
Gets the value of the given key as a Double.
key
- the key
ClassCastException
- if the value is not an double
Gets the value of the given key as a String.
key
- the key
ClassCastException
- if the value is not a String
Gets the value of the given key as a Boolean.
key
- the key
ClassCastException
- if the value is not an boolean
Gets the value of the given key as a primitive boolean.
key
- the key
defaultValue
- what to return if the value is null
ClassCastException
- if the value is not a boolean
Gets the value of the given key as an ObjectId.
key
- the key
ClassCastException
- if the value is not an ObjectId
Gets the value of the given key as a Date.
key
- the key
ClassCastException
- if the value is not a Date
Gets the list value of the given key, casting the list elements to the given Class<T>
. This is useful to avoid having casts in client code, though the effect is the same.
T
- the type of the class
key
- the key
clazz
- the non-null class to cast the list value to
ClassCastException
- if the elements in the list value of the given key is not of type T or the value is not a list
Gets the list value of the given key, casting the list elements to Class<T>
or returning the default list value if null. This is useful to avoid having casts in client code, though the effect is the same.
T
- the type of the class
key
- the key
clazz
- the non-null class to cast the list value to
defaultValue
- what to return if the value is null
ClassCastException
- if the value of the given key is not of type T
CodecConfigurationException
- if the document contains types not in the default registry
With the default DocumentCodec
.
writerSettings
- the json writer settings to use when encoding
CodecConfigurationException
- if the document contains types not in the default registry
With the default JsonWriterSettings
.
encoder
- the document codec instance to use to encode the document
CodecConfigurationException
- if the registry does not contain a codec for the document values.
Gets a JSON representation of this document
writerSettings
- the json writer settings to use when encoding
encoder
- the document codec instance to use to encode the document
CodecConfigurationException
- if the registry does not contain a codec for the document values.
public int size()
public boolean isEmpty()
containsValue
in interface Map<String,Object>
containsKey
in interface Map<String,Object>
public void clear()
public int hashCode()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4