BasicBSONObject
Date: 2015-03-03

org.bson

## Class BasicBSONObject

- java.lang.Object
- - java.util.AbstractMap<K,V>
  - - java.util.HashMap<K,V>
    - - java.util.LinkedHashMap<java.lang.String,java.lang.Object>
      - - org.bson.BasicBSONObject

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>, BSONObject

      public class BasicBSONObject
      extends java.util.LinkedHashMap<java.lang.String,java.lang.Object>
      implements BSONObject

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

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

  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.util.AbstractMap

      `java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicBSONObject()` Creates an empty object.
    `BasicBSONObject(int size)`
    `BasicBSONObject(java.util.Map<java.lang.String,java.lang.Object> m)` Creates a DBObject from a map.
    `BasicBSONObject(java.lang.String key, java.lang.Object value)` Convenience CTOR

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `BasicBSONObject` | `append(java.lang.String key, java.lang.Object val)` Add a key/value pair to this object
    `boolean` | `containsField(java.lang.String field)` Checks if this object contains a given field
    `boolean` | `containsKey(java.lang.String key)` Deprecated.
    `boolean` | `equals(java.lang.Object o)`
    `java.lang.Object` | `get(java.lang.String key)` Gets a value from this object
    `boolean` | `getBoolean(java.lang.String key)` Returns the value of a field as a boolean.
    `boolean` | `getBoolean(java.lang.String key, boolean def)` Returns the value of a field as a boolean
    `java.util.Date` | `getDate(java.lang.String field)` Returns the date or null if not set.
    `java.util.Date` | `getDate(java.lang.String field, java.util.Date def)` Returns the date or def if not set.
    `double` | `getDouble(java.lang.String key)` Returns the value of a field as a `double`.
    `double` | `getDouble(java.lang.String key, double def)` Returns the value of a field as an `double`.
    `int` | `getInt(java.lang.String key)` Returns the value of a field as an `int`.
    `int` | `getInt(java.lang.String key, int def)` Returns the value of a field as an `int`.
    `long` | `getLong(java.lang.String key)` Returns the value of a field as a `long`.
    `long` | `getLong(java.lang.String key, long def)` Returns the value of a field as an `long`.
    `ObjectId` | `getObjectId(java.lang.String field)` Returns the object id or null if not set.
    `ObjectId` | `getObjectId(java.lang.String field, ObjectId def)` Returns the object id or def if not set.
    `java.lang.String` | `getString(java.lang.String key)` Returns the value of a field as a string
    `java.lang.String` | `getString(java.lang.String key, java.lang.String def)` Returns the value of a field as a string
    `java.lang.Object` | `put(java.lang.String key, java.lang.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(java.util.Map m)` Sets all key/value pairs from a map into this object
    `java.lang.Object` | `removeField(java.lang.String key)` Deletes a field from this object.
    `java.util.Map<java.lang.String,java.lang.Object>` | `toMap()` Converts a DBObject to a map.
    `java.lang.String` | `toString()` Returns a JSON serialization of this object

    - ### Methods inherited from class java.util.LinkedHashMap

      `clear, containsValue, get`

    - ### 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

      `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(java.lang.String key,
                         java.lang.Object value)

      Convenience CTOR
      Parameters:
        `key` - key under which to store
        `value` - value to stor

    - #### BasicBSONObject

          public BasicBSONObject(java.util.Map<java.lang.String,java.lang.Object> m)

      Creates a DBObject from a map.
      Parameters:
        `m` - map to convert

  - ### Method Detail

    - #### toMap

          public java.util.Map<java.lang.String,java.lang.Object> toMap()

      Converts a DBObject to a map.
      Specified by:
        `toMap` in interface `BSONObject`
      Returns:
        the DBObject

    - #### removeField

          public java.lang.Object removeField(java.lang.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(java.lang.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(java.lang.String key)

      Deprecated.
      Description copied from interface: `BSONObject`
      Deprecated
      Specified by:
        `containsKey` in interface `BSONObject`
      Returns:
        True if the key is present

    - #### get

          public java.lang.Object get(java.lang.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(java.lang.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(java.lang.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(java.lang.String key)

      Returns the value of a field as a `long`.
      Parameters:
        `key` - the field to return
      Returns:
        the field value

    - #### getLong

          public long getLong(java.lang.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)

    - #### getDouble

          public double getDouble(java.lang.String key)

      Returns the value of a field as a `double`.
      Parameters:
        `key` - the field to return
      Returns:
        the field value

    - #### getDouble

          public double getDouble(java.lang.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)

    - #### getString

          public java.lang.String getString(java.lang.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

    - #### getString

          public java.lang.String getString(java.lang.String key,
                                   java.lang.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

    - #### getBoolean

          public boolean getBoolean(java.lang.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

    - #### getBoolean

          public boolean getBoolean(java.lang.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

    - #### getObjectId

          public ObjectId getObjectId(java.lang.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 :-^).

    - #### getObjectId

          public ObjectId getObjectId(java.lang.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.

    - #### getDate

          public java.util.Date getDate(java.lang.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.

    - #### getDate

          public java.util.Date getDate(java.lang.String field,
                               java.util.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.

    - #### put

          public java.lang.Object put(java.lang.String key,
                             java.lang.Object val)

      Add a key/value pair to this object
      Specified by:
        `put` in interface `java.util.Map<java.lang.String,java.lang.Object>`
      Specified by:
        `put` in interface `BSONObject`
      Overrides:
        `put` in class `java.util.HashMap<java.lang.String,java.lang.Object>`
      Parameters:
        `key` - the field name
        `val` - the field value
      Returns:
        the `val` parameter

    - #### putAll

          public void putAll(java.util.Map m)

      Description copied from interface: `BSONObject`
      Sets all key/value pairs from a map into this object
      Specified by:
        `putAll` in interface `java.util.Map<java.lang.String,java.lang.Object>`
      Specified by:
        `putAll` in interface `BSONObject`
      Overrides:
        `putAll` in class `java.util.HashMap<java.lang.String,java.lang.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(java.lang.String key,
                               java.lang.Object val)

      Add a key/value pair to this object
      Parameters:
        `key` - the field name
        `val` - the field value
      Returns:
        `this`

    - #### toString

          public java.lang.String toString()

      Returns a JSON serialization of this object
      Overrides:
        `toString` in class `java.util.AbstractMap<java.lang.String,java.lang.Object>`
      Returns:
        JSON serialization

    - #### equals

          public boolean equals(java.lang.Object o)

      Specified by:
        `equals` in interface `java.util.Map<java.lang.String,java.lang.Object>`
      Overrides:
        `equals` in class `java.util.AbstractMap<java.lang.String,java.lang.Object>`