public class

BasicBSONObject

extends LinkedHashMap<K, V>
implements BSONObject
java.lang.Object
   ↳ java.util.AbstractMap<K, V>
     ↳ java.util.HashMap<K, V>
       ↳ java.util.LinkedHashMap<K, V>
         ↳ org.bson.BasicBSONObject
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A simple implementation of DBObject. A DBObject can be created as follows, using this class:

 DBObject obj = new BasicBSONObject();
 obj.put( "foo", "bar" );
 

Summary

Public Constructors
BasicBSONObject()
Creates an empty object.
BasicBSONObject(int size)
BasicBSONObject(String key, Object value)
Convenience CTOR
BasicBSONObject(Map m)
Creates a DBObject from a map.
Public Methods
BasicBSONObject append(String key, Object val)
Add a key/value pair to this object
boolean containsField(String field)
Checks if this object contains a given field
boolean containsKey(String key)
This method is deprecated. No replacement.
boolean equals(Object o)
Object get(String key)
Gets a value from this object
boolean getBoolean(String key, boolean def)
Returns the value of a field as a boolean
boolean getBoolean(String key)
Returns the value of a field as a boolean.
Date getDate(String field, Date def)
Returns the date or def if not set.
Date getDate(String field)
Returns the date or null if not set.
double getDouble(String key, double def)
Returns the value of a field as an double.
double getDouble(String key)
Returns the value of a field as a double.
int getInt(String key)
Returns the value of a field as an int.
int getInt(String key, int def)
Returns the value of a field as an int.
long getLong(String key, long def)
Returns the value of a field as an long.
long getLong(String key)
Returns the value of a field as a long.
ObjectId getObjectId(String field)
Returns the object id or null if not set.
ObjectId getObjectId(String field, ObjectId def)
Returns the object id or def if not set.
String getString(String key, String def)
Returns the value of a field as a string
String getString(String key)
Returns the value of a field as a string
Object put(String key, Object val)
Add a key/value pair to this object
void putAll(Map m)
void putAll(BSONObject o)
Sets all key/value pairs from an object into this object
Object removeField(String key)
Deletes a field from this object.
Map toMap()
Converts a DBObject to a map.
String toString()
Returns a JSON serialization of this object
[Expand]
Inherited Methods
From class java.util.LinkedHashMap
From class java.util.HashMap
From class java.util.AbstractMap
From class java.lang.Object
From interface java.util.Map
From interface org.bson.BSONObject

Public Constructors

public BasicBSONObject ()

Creates an empty object.

public BasicBSONObject (int size)

public BasicBSONObject (String key, Object value)

Convenience CTOR

Parameters
key key under which to store
value value to stor

public BasicBSONObject (Map m)

Creates a DBObject from a map.

Parameters
m map to convert

Public Methods

public BasicBSONObject append (String key, Object val)

Add a key/value pair to this object

Parameters
key the field name
val the field value
Returns
  • this

public boolean containsField (String field)

Checks if this object contains a given field

Parameters
field field name
Returns
  • if the field exists

public boolean containsKey (String key)

This method is deprecated.
No replacement.

Deprecated

Returns
  • True if the key is present

public boolean equals (Object o)

public Object get (String key)

Gets a value from this object

Parameters
key field name
Returns
  • the value

public boolean getBoolean (String key, boolean def)

Returns the value of a field as a boolean

Parameters
key the field to look up
def the default value in case the field is not found
Returns
  • the value of the field, converted to a string

public boolean getBoolean (String key)

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

public Date getDate (String field, Date def)

Returns the date or def if not set.

Parameters
field The field to return
def the default value in case the field is not found
Returns
  • The field object value or def if not set.

public Date getDate (String field)

Returns the date or null if not set.

Parameters
field The field to return
Returns
  • The field object value or null if not found.

public double getDouble (String key, double def)

Returns the value of a field as an double.

Parameters
key the field to look for
def the default to return
Returns
  • the field value (or default)

public double getDouble (String key)

Returns the value of a field as a double.

Parameters
key the field to return
Returns
  • the field value

public int getInt (String key)

Returns the value of a field as an int.

Parameters
key the field to look for
Returns
  • the field value (or default)

public int getInt (String key, int def)

Returns the value of a field as an int.

Parameters
key the field to look for
def the default to return
Returns
  • the field value (or default)

public long getLong (String key, long def)

Returns the value of a field as an long.

Parameters
key the field to look for
def the default to return
Returns
  • the field value (or default)

public long getLong (String key)

Returns the value of a field as a long.

Parameters
key the field to return
Returns
  • the field value

public ObjectId getObjectId (String field)

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 :-^).

public ObjectId getObjectId (String field, ObjectId def)

Returns the object id or def if not set.

Parameters
field The field to return
def the default value in case the field is not found
Returns
  • The field object value or def if not set.

public String getString (String key, String def)

Returns the value of a field as a string

Parameters
key the field to look up
def the default to return
Returns
  • the value of the field, converted to a string

public String getString (String key)

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

public Object put (String key, Object val)

Add a key/value pair to this object

Parameters
key the field name
val the field value
Returns
  • the val parameter

public void putAll (Map m)

public void putAll (BSONObject o)

Sets all key/value pairs from an object into this object

Parameters
o the object

public Object removeField (String key)

Deletes a field from this object.

Parameters
key the field name to remove
Returns
  • the object removed

public Map toMap ()

Converts a DBObject to a map.

Returns
  • the DBObject

public String toString ()

Returns a JSON serialization of this object

Returns
  • JSON serialization