public class

BasicBSONList

extends ArrayList<E>
implements BSONObject
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractList<E>
       ↳ java.util.ArrayList<E>
         ↳ org.bson.types.BasicBSONList
Known Direct Subclasses

Class Overview

Utility class to allow array DBObjects to be created.

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

 DBObject 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
 

Summary

[Expand]
Inherited Fields
From class java.util.AbstractList
Public Constructors
BasicBSONList()
Public Methods
boolean containsField(String key)
Checks if this object contains a field with the given name.
boolean containsKey(String key)
This method is deprecated. No replacement.
Object get(String key)
Gets a value at an index.
Set<String> keySet()
Returns this object's fields' names
Object put(String key, Object v)
Puts a value at an index.
Object put(int key, Object v)
Puts a value at an index.
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)
Removes a field with a given name from this object.
Map toMap()
Returns a map representing this BSONObject.
[Expand]
Inherited Methods
From class java.util.ArrayList
From class java.util.AbstractList
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface java.util.List
From interface org.bson.BSONObject

Public Constructors

public BasicBSONList ()

Public Methods

public boolean containsField (String key)

Checks if this object contains a field with the given name.

Parameters
key Field name for which to check
Returns
  • True if the field is present

public boolean containsKey (String key)

This method is deprecated.
No replacement.

Deprecated

Returns
  • True if the key is present

public Object get (String key)

Gets a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.

Parameters
key the index
Returns
  • the value, if found, or null
Throws
IllegalArgumentException if key cannot be parsed into an int

public Set<String> keySet ()

Returns this object's fields' names

Returns
  • The names of the fields in this object

public Object put (String key, Object v)

Puts a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.

Parameters
key the index at which to insert the value
v the value to insert
Returns
  • the value
Throws
IllegalArgumentException if key cannot be parsed into an int

public Object put (int key, Object v)

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
v the value to insert
Returns
  • the value

public void putAll (BSONObject o)

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

Parameters
o the object

public void putAll (Map m)

Sets all key/value pairs from a map into this object

Parameters
m the map

public Object removeField (String key)

Removes a field with a given name from this object.

Parameters
key The name of the field to remove
Returns
  • The value removed from this object

public Map toMap ()

Returns a map representing this BSONObject.

Returns
  • the map