Package org.bson
Class BasicBSONObject
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,Object> BSONObject
A simple implementation of
DBObject. A DBObject can be created as follows, using this class: DBObject obj = new
BasicBSONObject(); obj.put( "foo", "bar" ); - See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty object.BasicBSONObject(int size) Creates an empty object.BasicBSONObject(String key, Object value) Creates a BSONObject initialised with a single key/value pair.BasicBSONObject(Map map) Creates a DBObject from a map. -
Method Summary
Modifier and TypeMethodDescriptionAdd a key/value pair to this objectbooleancontainsField(String field) Checks if this object contains a given fieldbooleanCompares two documents according to their serialized form, ignoring the order of keys.Gets a value from this objectbooleangetBoolean(String key) Returns the value of a field as a boolean.booleangetBoolean(String key, boolean def) Returns the value of a field as a booleanReturns the date or null if not set.Returns the date or def if not set.doubleReturns the value of a field as adouble.doubleReturns the value of a field as andouble.intReturns the value of a field as anint.intReturns the value of a field as anint.longReturns the value of a field as along.longReturns the value of a field as anlong.getObjectId(String field) Returns the object id or null if not set.getObjectId(String field, ObjectId def) Returns the object id or def if not set.Returns the value of a field as a stringReturns the value of a field as a stringinthashCode()voidSets all key/value pairs from a map into this objectvoidputAll(BSONObject o) Sets all key/value pairs from an object into this objectremoveField(String key) Deletes a field from this object.toMap()Converts a DBObject to a map.Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMap
toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.bson.BSONObject
keySet, putMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size
-
Constructor Details
-
BasicBSONObject
public BasicBSONObject()Creates an empty object. -
BasicBSONObject
public BasicBSONObject(int size) Creates an empty object.- Parameters:
size- the initial capacity for the Map storing this document.
-
BasicBSONObject
Creates a BSONObject initialised with a single key/value pair.- Parameters:
key- key under which to storevalue- value to store
-
BasicBSONObject
Creates a DBObject from a map.- Parameters:
map- map to convert
-
-
Method Details
-
toMap
Converts a DBObject to a map.- Specified by:
toMapin interfaceBSONObject- Returns:
- the DBObject
-
removeField
Deletes a field from this object.- Specified by:
removeFieldin interfaceBSONObject- Parameters:
key- the field name to remove- Returns:
- the object removed
-
containsField
Checks if this object contains a given field- Specified by:
containsFieldin interfaceBSONObject- Parameters:
field- field name- Returns:
- if the field exists
-
get
Gets a value from this object- Specified by:
getin interfaceBSONObject- Parameters:
key- field name- Returns:
- the value
-
getInt
Returns the value of a field as anint.- Parameters:
key- the field to look for- Returns:
- the field value (or default)
-
getInt
Returns the value of a field as anint.- Parameters:
key- the field to look fordef- the default to return- Returns:
- the field value (or default)
-
getLong
Returns the value of a field as along.- Parameters:
key- the field to return- Returns:
- the field value
-
getLong
Returns the value of a field as anlong.- Parameters:
key- the field to look fordef- the default to return- Returns:
- the field value (or default)
-
getDouble
Returns the value of a field as adouble.- Parameters:
key- the field to return- Returns:
- the field value
-
getDouble
Returns the value of a field as andouble.- Parameters:
key- the field to look fordef- the default to return- Returns:
- the field value (or default)
-
getString
Returns the value of a field as a string- Parameters:
key- the field to look up- Returns:
- the value of the field, converted to a string
-
getString
Returns the value of a field as a string- Parameters:
key- the field to look updef- the default to return- Returns:
- the value of the field, converted to a string
-
getBoolean
Returns the value of a field as a boolean.- Parameters:
key- the field to look up- Returns:
- the value of the field, or false if field does not exist
-
getBoolean
Returns the value of a field as a boolean- Parameters:
key- the field to look updef- the default value in case the field is not found- Returns:
- the value of the field, converted to a string
-
getObjectId
Returns the object id or null if not set.- Parameters:
field- The field to return- Returns:
- The field object value or null if not found (or if null :-^).
-
getObjectId
Returns the object id or def if not set.- Parameters:
field- The field to returndef- the default value in case the field is not found- Returns:
- The field object value or def if not set.
-
getDate
Returns the date or null if not set.- Parameters:
field- The field to return- Returns:
- The field object value or null if not found.
-
getDate
Returns the date or def if not set.- Parameters:
field- The field to returndef- the default value in case the field is not found- Returns:
- The field object value or def if not set.
-
putAll
Description copied from interface:BSONObjectSets all key/value pairs from a map into this object -
putAll
Description copied from interface:BSONObjectSets all key/value pairs from an object into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
o- the object
-
append
Add a key/value pair to this object- Parameters:
key- the field nameval- the field value- Returns:
this
-
equals
Compares two documents according to their serialized form, ignoring the order of keys.- Specified by:
equalsin interfaceMap<String,Object> - Overrides:
equalsin classAbstractMap<String,Object> - Parameters:
o- the document to compare to, which must be an instance ofBSONObject.- Returns:
- true if the documents have the same serialized form, ignoring key order.
-
hashCode
public int hashCode()
-