Class BasicBSONList

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.lang.Object>, java.util.Collection<java.lang.Object>, java.util.List<java.lang.Object>, java.util.RandomAccess, BSONObject
    Direct Known Subclasses:
    BasicDBList

    public class BasicBSONList
    extends java.util.ArrayList<java.lang.Object>
    implements BSONObject

    Utility class to allow array DBObjects to be created.

    Note: MongoDB will also create arrays from java.util .Lists.

     BSONObject obj = new BasicBSONList();
     obj.put( "0", value1 );
     obj.put( "4", value2 );
     obj.put( 2, value3 );
     

    This simulates the array [ value1, null, value3, null, value2 ] by creating the DBObject { "0" : value1, "1" : null, "2" : value3, "3" : null, "4" : value2 }.

    BasicBSONList only supports numeric keys. Passing strings that cannot be converted to ints will cause an IllegalArgumentException.

     BasicBSONList list = new BasicBSONList();
     list.put("1", "bar"); // ok
     list.put("1E1", "bar"); // throws exception
     
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      BasicBSONList()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean containsField​(java.lang.String key)
      Checks if this object contains a field with the given name.
      boolean containsKey​(java.lang.String key)
      Deprecated.
      java.lang.Object get​(java.lang.String key)
      Gets a value at an index.
      java.util.Set<java.lang.String> keySet()
      Returns this object's fields' names
      java.lang.Object put​(int key, java.lang.Object value)
      Puts a value at an index.
      java.lang.Object put​(java.lang.String key, java.lang.Object v)
      Puts a value at an index.
      void putAll​(java.util.Map 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
      java.lang.Object removeField​(java.lang.String key)
      Removes a field with a given name from this object.
      java.util.Map toMap()
      Returns a map representing this BSONObject.
      • Methods inherited from class java.util.ArrayList

        add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
      • Methods inherited from class java.util.AbstractCollection

        containsAll, toString
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
      • Methods inherited from interface java.util.List

        containsAll
    • Constructor Detail

      • BasicBSONList

        public BasicBSONList()
    • Method Detail

      • put

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.Object v)
        Puts a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.
        Specified by:
        put in interface BSONObject
        Parameters:
        key - the index at which to insert the value
        v - the value to insert
        Returns:
        the value
        Throws:
        java.lang.IllegalArgumentException - if key cannot be parsed into an int
      • put

        public java.lang.Object put​(int key,
                                    java.lang.Object value)
        Puts a value at an index. This will fill any unset indexes less than index with null.
        Parameters:
        key - the index at which to insert the value
        value - the value to insert
        Returns:
        the value
      • 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 BSONObject
        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
      • get

        public java.lang.Object get​(java.lang.String key)
        Gets a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.
        Specified by:
        get in interface BSONObject
        Parameters:
        key - the index
        Returns:
        the value, if found, or null
        Throws:
        java.lang.IllegalArgumentException - if key cannot be parsed into an int
      • removeField

        public java.lang.Object removeField​(java.lang.String key)
        Description copied from interface: BSONObject
        Removes a field with a given name from this object.
        Specified by:
        removeField in interface BSONObject
        Parameters:
        key - The name of the field to remove
        Returns:
        The value removed from this object
      • containsKey

        @Deprecated
        public boolean containsKey​(java.lang.String 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
      • containsField

        public boolean containsField​(java.lang.String key)
        Description copied from interface: BSONObject
        Checks if this object contains a field with the given name.
        Specified by:
        containsField in interface BSONObject
        Parameters:
        key - Field name for which to check
        Returns:
        True if the field is present
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Description copied from interface: BSONObject
        Returns this object's fields' names
        Specified by:
        keySet in interface BSONObject
        Returns:
        The names of the fields in this object
      • toMap

        public java.util.Map toMap()
        Description copied from interface: BSONObject
        Returns a map representing this BSONObject.
        Specified by:
        toMap in interface BSONObject
        Returns:
        the map