Package org.bson

Class BasicBSONObject

  • All Implemented Interfaces:
    , , <,​>, BSONObject
    Direct Known Subclasses:
    BasicDBObject

    public class BasicBSONObject
    extends <,​>
    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.

        < extends ,​ extends >, < extends ,​ extends >
    • Constructor Summary

      Constructors 
      Constructor Description
      BasicBSONObject()
      Creates an empty object.
      BasicBSONObject​(int size)
      Creates an empty object.
       key,  value)
      Creates a BSONObject initialised with a single key/value pair.
       map)
      Creates a DBObject from a map.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      BasicBSONObject  key,  val)
      Add a key/value pair to this object
      boolean  field)
      Checks if this object contains a given field
      boolean  key)
      Deprecated.
      boolean  o)
      Compares two documents according to their serialized form, ignoring the order of keys.
       key)
      Gets a value from this object
      boolean  key)
      Returns the value of a field as a boolean.
      boolean  key, boolean def)
      Returns the value of a field as a boolean
       field)
      Returns the date or null if not set.
       field,  def)
      Returns the date or def if not set.
      double  key)
      Returns the value of a field as a double.
      double  key, double def)
      Returns the value of a field as an double.
      int  key)
      Returns the value of a field as an int.
      int  key, int def)
      Returns the value of a field as an int.
      long  key)
      Returns the value of a field as a long.
      long  key, long def)
      Returns the value of a field as an long.
      ObjectId  field)
      Returns the object id or null if not set.
      ObjectId  field, ObjectId def)
      Returns the object id or def if not set.
       key)
      Returns the value of a field as a string
       key,  def)
      Returns the value of a field as a string
      int hashCode()  
      void  m)
      Sets all key/value pairs from a map into this object
      void putAll​(BSONObject o)
      Sets all key/value pairs from an object into this object
       key)
      Deletes a field from this object.
      toMap()
      Converts a DBObject to a map.
      • Methods inherited from class java.util.

        , , , , , , , , ,
      • Methods inherited from class java.util.

        , , , , , , , , , , , , ,
      • Methods inherited from class java.util.

      • Methods inherited from class java.lang.

        , , , , , ,
      • Methods inherited from interface java.util.

        , , , , , , , , , , , ,
    • Constructor Detail

      • 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

        public BasicBSONObject​( key,
                                value)
        Creates a BSONObject initialised with a single key/value pair.
        Parameters:
        key - key under which to store
        value - value to store
      • BasicBSONObject

        public BasicBSONObject​( map)
        Creates a DBObject from a map.
        Parameters:
        map - map to convert
    • Method Detail

      • toMap

        public  toMap()
        Converts a DBObject to a map.
        Specified by:
        toMap in interface BSONObject
        Returns:
        the DBObject
      • removeField

        public  removeField​( 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​( 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

        public boolean containsKey​( key)
        Deprecated.
        Description copied from interface: BSONObject
        Deprecated
        Specified by:
        containsKey in interface BSONObject
        Parameters:
        key - the key to check
        Returns:
        True if the key is present
      • get

        public  get​( key)
        Gets a value from this object
        Specified by:
        get in interface BSONObject
        Parameters:
        key - field name
        Returns:
        the value
      • getInt

        public int getInt​( 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​( 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​( key)
        Returns the value of a field as a long.
        Parameters:
        key - the field to return
        Returns:
        the field value
      • getLong

        public long getLong​( 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​( key)
        Returns the value of a field as a double.
        Parameters:
        key - the field to return
        Returns:
        the field value
      • getDouble

        public double getDouble​( 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  getString​( 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  getString​( key,
                                 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​( 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​( 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  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  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  getDate​( 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  getDate​( field,
                             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.
      • putAll

        public void putAll​( m)
        Description copied from interface: BSONObject
        Sets all key/value pairs from a map into this object
        Specified by:
        putAll in interface BSONObject
        Specified by:
         in interface <,​>
        Overrides:
         in class <,​>
        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  key,
                                       val)
        Add a key/value pair to this object
        Parameters:
        key - the field name
        val - the field value
        Returns:
        this
      • equals

        public boolean equals​( o)
        Compares two documents according to their serialized form, ignoring the order of keys.
        Specified by:
         in interface <,​>
        Overrides:
         in class <,​>
        Parameters:
        o - the document to compare to, which must be an instance of BSONObject.
        Returns:
        true if the documents have the same serialized form, ignoring key order.
      • hashCode

        public int hashCode()
        Specified by:
         in interface <,​>
        Overrides:
         in class <,​>