@SerializeWith(value=DocumentExternalizer.class) public class BasicDocument extends LinkedHashMap<String,Object> implements MutableDocument
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Document.Field, Document.ValueTransformer
Constructor and Description |
---|
BasicDocument() |
BasicDocument(Document document) |
BasicDocument(int initialCapacity) |
BasicDocument(String name,
Object value) |
BasicDocument(String name1,
Object value1,
String name2,
Object value2) |
BasicDocument(String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3) |
BasicDocument(String name1,
Object value1,
String name2,
Object value2,
String name3,
Object value3,
String name4,
Object value4) |
Modifier and Type | Method and Description |
---|---|
Document |
clone()
Obtain a clone of this document.
|
boolean |
containsAll(Document document)
Checks if this object contains all of the fields in the supplied document.
|
boolean |
containsField(String name)
Checks if this object contains a field with the given name.
|
boolean |
equals(Object obj) |
Iterable<Document.Field> |
fields()
Obtain an iterator over the
Document.Field s in this object. |
Object |
get(String name)
Gets the value in this document for the given field name.
|
List<?> |
getArray(String name)
Get the array value in this document for the given field name.
|
Binary |
getBinary(String name)
Get the
Binary value in this document for the given field name. |
Boolean |
getBoolean(String name)
Get the boolean value in this document for the given field name.
|
boolean |
getBoolean(String name,
boolean defaultValue)
Get the boolean value in this document for the given field name.
|
Code |
getCode(String name)
Get the
Code value in this document for the given field name. |
CodeWithScope |
getCodeWithScope(String name)
Get the
CodeWithScope value in this document for the given field name. |
Document |
getDocument(String name)
Get the document value in this document for the given field name.
|
Double |
getDouble(String name)
Get the double value in this document for the given field name.
|
double |
getDouble(String name,
double defaultValue)
Get the double value in this document for the given field name.
|
Integer |
getInteger(String name)
Get the integer value in this document for the given field name.
|
int |
getInteger(String name,
int defaultValue)
Get the integer value in this document for the given field name.
|
Long |
getLong(String name)
Get the integer value in this document for the given field name.
|
long |
getLong(String name,
long defaultValue)
Get the long value in this document for the given field name.
|
MaxKey |
getMaxKey(String name)
Get the
MaxKey value in this document for the given field name. |
MinKey |
getMinKey(String name)
Get the
MinKey value in this document for the given field name. |
Number |
getNumber(String name)
Get the number value in this document for the given field name.
|
Number |
getNumber(String name,
Number defaultValue)
Get the number value in this document for the given field name.
|
ObjectId |
getObjectId(String name)
Get the
ObjectId value in this document for the given field name. |
Pattern |
getPattern(String name)
Get the
Pattern value in this document for the given field name. |
String |
getString(String name)
Get the string value in this document for the given field name.
|
String |
getString(String name,
String defaultValue)
Get the string value in this document for the given field name.
|
Symbol |
getSymbol(String name)
Get the
Symbol value in this document for the given field name. |
int |
getType(String name)
Get the
Bson.Type constant that describes the type of value for the given field name. |
UUID |
getUuid(String name)
Get the
UUID value in this document for the given field name. |
UUID |
getUuid(String name,
UUID defaultValue)
Get the
UUID value in this document for the given field name. |
boolean |
isNull(String name)
Determine whether this object has a pair with the given the name and the value is null.
|
boolean |
isNullOrMissing(String name)
Determine whether this object has a pair with the given the name and the value is null, or if this object has no field with
the given name.
|
void |
putAll(Document object)
Sets on this object all name/value pairs from the supplied object.
|
Object |
remove(String name)
Removes from this object the name/value pair with the given name.
|
void |
removeAll()
Remove all fields from this document.
|
Map<String,?> |
toMap()
Returns a map representing this BSONObject.
|
String |
toString() |
protected Object |
unwrap(Object value) |
Document |
with(Document.ValueTransformer transformer)
Obtain a clone of this document, but with the field values transformed using the supplied
Document.ValueTransformer . |
Document |
with(Map<String,Object> changedFields)
Obtain a clone of this document, but with the supplied fields replaced.
|
Document |
with(String fieldName,
Object newValue)
Obtain a clone of this document, but with the supplied fields replaced.
|
Document |
withVariablesReplaced(Properties properties)
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the
supplied properties.
|
Document |
withVariablesReplacedWithSystemProperties()
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the
System properties.
|
clear, containsValue, get, removeEldestEntry
containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
hashCode
finalize, getClass, notify, notifyAll, wait, wait, wait
put, putAll
public BasicDocument()
public BasicDocument(Document document)
public BasicDocument(int initialCapacity)
public BasicDocument(String name1, Object value1, String name2, Object value2, String name3, Object value3)
public boolean containsField(String name)
Document
containsField
in interface Document
name
- The name of the pair for which to checkpublic boolean containsAll(Document document)
Document
containsAll
in interface Document
document
- The document with the fields that should be in this documentpublic Object get(String name)
Document
public Map<String,?> toMap()
Document
public Iterable<Document.Field> fields()
Document
Document.Field
s in this object.public Boolean getBoolean(String name)
Document
getBoolean
in interface Document
name
- The name of the pairpublic boolean getBoolean(String name, boolean defaultValue)
Document
getBoolean
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a booleandefaultValue
if there is no such pair or if the value is not a
booleanpublic Integer getInteger(String name)
Document
getInteger
in interface Document
name
- The name of the pairpublic int getInteger(String name, int defaultValue)
Document
getInteger
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a integerdefaultValue
if there is no such pair or if the value is not a
integerpublic Long getLong(String name)
Document
public long getLong(String name, long defaultValue)
Document
getLong
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a long valuedefaultValue
if there is no such pair or if the value is not a long
valuepublic Double getDouble(String name)
Document
public double getDouble(String name, double defaultValue)
Document
public Number getNumber(String name)
Document
public Number getNumber(String name, Number defaultValue)
Document
public String getString(String name)
Document
Symbol
.public String getString(String name, String defaultValue)
Document
Symbol
.public List<?> getArray(String name)
Document
public Document getDocument(String name)
Document
getDocument
in interface Document
name
- The name of the pairpublic boolean isNull(String name)
Document
this.get(name) instanceof Null;
isNull
in interface Document
name
- The name of the pairtrue
if the field has been set to a Null
value, or false otherwiseDocument.isNullOrMissing(String)
public boolean isNullOrMissing(String name)
Document
Null.matches(this.get(name));
isNullOrMissing
in interface Document
name
- The name of the pairtrue
if the field value for the name is null or if there is no such field.Document.isNull(String)
public MaxKey getMaxKey(String name)
Document
MaxKey
value in this document for the given field name.public MinKey getMinKey(String name)
Document
MinKey
value in this document for the given field name.public Code getCode(String name)
Document
Code
value in this document for the given field name.public CodeWithScope getCodeWithScope(String name)
Document
CodeWithScope
value in this document for the given field name.getCodeWithScope
in interface Document
name
- The name of the pairCodeWithScope
field value, if found, or null if there is no such pair or if the value is not a
CodeWithScope
public ObjectId getObjectId(String name)
Document
ObjectId
value in this document for the given field name.getObjectId
in interface Document
name
- The name of the pairObjectId
field value, if found, or null if there is no such pair or if the value is not a
ObjectId
public Binary getBinary(String name)
Document
Binary
value in this document for the given field name.public Symbol getSymbol(String name)
Document
Symbol
value in this document for the given field name.public Pattern getPattern(String name)
Document
Pattern
value in this document for the given field name.getPattern
in interface Document
name
- The name of the pairPattern
field value, if found, or null if there is no such pair or if the value is not a
Pattern
public UUID getUuid(String name)
Document
UUID
value in this document for the given field name.public UUID getUuid(String name, UUID defaultValue)
Document
UUID
value in this document for the given field name.getUuid
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a stringUUID
field value if found, or defaultValue
if there is no such pair or if the value is not
a UUID (or a string that is convertable from a UUID)public int getType(String name)
Document
Bson.Type
constant that describes the type of value for the given field name.public void putAll(Document object)
MutableDocument
putAll
in interface MutableDocument
object
- the object containing the name/value pairs to be set on this objectpublic Object remove(String name)
MutableDocument
remove
in interface MutableDocument
name
- The name of the pair to removepublic void removeAll()
MutableDocument
removeAll
in interface MutableDocument
public boolean equals(Object obj)
public String toString()
toString
in class AbstractMap<String,Object>
public Document clone()
Document
public Document with(Map<String,Object> changedFields)
Document
public Document with(String fieldName, Object newValue)
Document
public Document with(Document.ValueTransformer transformer)
Document
Document.ValueTransformer
.public Document withVariablesReplaced(Properties properties)
Document
Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := /* any characters except ',' and ':' and '}' defaultValue := /* any characters exceptNote that variableName is the name used to look up the
Properties
property.
Notice that the syntax supports multiple variables. The logic will process the variables from let to right,
until an existing System property is found. And at that point, it will stop and will not attempt to find values for the
other variables.
withVariablesReplaced
in interface Document
properties
- the properties keyed by variable nameDocument.withVariablesReplacedWithSystemProperties()
,
Document.with(ValueTransformer)
,
SchemaLibrary.convertValues(Document, String)
public Document withVariablesReplacedWithSystemProperties()
Document
Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := /* any characters except ',' and ':' and '}' defaultValue := /* any characters exceptNote that variableName is the name used to look up a System property via
System.getProperty(String)
.
Notice that the syntax supports multiple variables. The logic will process the variables from let to right,
until an existing System property is found. And at that point, it will stop and will not attempt to find values for the
other variables.
Because only string values can contain variables, the resulting values are left as strings. This may not be valid according
to the document's JSON Schema, so see SchemaLibrary.convertValues(Document, String)
to convert the string values
after variable substitution into the expected non-string types.
withVariablesReplacedWithSystemProperties
in interface Document
Document.withVariablesReplaced(Properties)
,
Document.with(ValueTransformer)
,
SchemaLibrary.convertValues(Document, String)
Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.