org.bson
Class BasicBSONObject

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<String,Object>
              extended by org.bson.BasicBSONObject
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>, BSONObject
Direct Known Subclasses:
BasicDBObject

public class BasicBSONObject
extends LinkedHashMap<String,Object>
implements 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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
BasicBSONObject()
          Creates an empty object.
BasicBSONObject(int size)
           
BasicBSONObject(Map m)
          Creates a DBObject from a map.
BasicBSONObject(String key, Object value)
          Convenience CTOR
 
Method Summary
 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)
          Deprecated.  
 boolean equals(Object o)
           
 Object get(String key)
          Gets a value from this object
 boolean getBoolean(String key, boolean def)
           
 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)
          Returns the value of a field as a long.
 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(BSONObject o)
          Sets all key/value pairs from an object into this object
 void putAll(Map m)
          Sets all key/value pairs from a map 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
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, remove, size, values
 
Methods inherited from class java.util.AbstractMap
hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.bson.BSONObject
keySet
 
Methods inherited from interface java.util.Map
containsKey, entrySet, hashCode, isEmpty, keySet, remove, size, values
 

Constructor Detail

BasicBSONObject

public BasicBSONObject()
Creates an empty object.


BasicBSONObject

public BasicBSONObject(int size)

BasicBSONObject

public BasicBSONObject(String key,
                       Object value)
Convenience CTOR

Parameters:
key - key under which to store
value - value to stor

BasicBSONObject

public BasicBSONObject(Map m)
Creates a DBObject from a map.

Parameters:
m - map to convert
Method Detail

toMap

public Map toMap()
Converts a DBObject to a map.

Specified by:
toMap in interface BSONObject
Returns:
the DBObject

removeField

public Object removeField(String key)
Deletes a field from this object.

Specified by:
removeField in interface BSONObject
Parameters:
key - the field name to remove
Returns:
the object removed

containsField

public boolean containsField(String field)
Checks if this object contains a given field

Specified by:
containsField in interface BSONObject
Parameters:
field - field name
Returns:
if the field exists

containsKey

@Deprecated
public boolean containsKey(String key)
Deprecated. 

Description copied from interface: BSONObject
Deprecated

Specified by:
containsKey in interface BSONObject
Returns:

get

public Object get(String key)
Gets a value from this object

Specified by:
get in interface BSONObject
Parameters:
key - field name
Returns:
the value

getInt

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)

getInt

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)

getLong

public long getLong(String key)
Returns the value of a field as a long.

Parameters:
key - the field to return
Returns:
the field value

getDouble

public double getDouble(String key)
Returns the value of a field as a double.

Parameters:
key - the field to return
Returns:
the field value

getString

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

getBoolean

public boolean getBoolean(String key,
                          boolean def)

put

public Object put(String key,
                  Object val)
Add a key/value pair to this object

Specified by:
put in interface Map<String,Object>
Specified by:
put in interface BSONObject
Overrides:
put in class HashMap<String,Object>
Parameters:
key - the field name
val - the field value
Returns:
the val parameter

putAll

public void putAll(Map m)
Description copied from interface: BSONObject
Sets all key/value pairs from a map into this object

Specified by:
putAll in interface Map<String,Object>
Specified by:
putAll in interface BSONObject
Overrides:
putAll in class HashMap<String,Object>
Parameters:
m - the map

putAll

public void putAll(BSONObject o)
Description copied from interface: BSONObject
Sets all key/value pairs from an object into this object

Specified by:
putAll in interface BSONObject
Parameters:
o - the object

append

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:
the val parameter

toString

public String toString()
Returns a JSON serialization of this object

Overrides:
toString in class AbstractMap<String,Object>
Returns:
JSON serialization

equals

public boolean equals(Object o)
Specified by:
equals in interface Map<String,Object>
Overrides:
equals in class AbstractMap<String,Object>