com.mongodb
Class BasicDBList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Object>
              extended by com.mongodb.BasicDBList
All Implemented Interfaces:
DBObject, Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess

public class BasicDBList
extends ArrayList<Object>
implements DBObject

Utility class to allow array DBObjects to be created.

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

 DBObject obj = new BasicDBList();
 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 }.

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

 BasicDBList list = new BasicDBList();
 list.put("1", "bar"); // ok
 list.put("1E1", "bar"); // throws exception
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BasicDBList()
           
 
Method Summary
 boolean containsField(String key)
          Checks if this object contains a field with the given name.
 boolean containsKey(String key)
          Deprecated.  
 Object get(String key)
          Gets a value at an index.
 boolean isPartialObject()
          whether markAsPartialObject was ever called only matters if you are going to upsert and dont' want to risk losing fields
 Set<String> keySet()
          Returns this object's fields' names
 void markAsPartialObject()
          if this object was loaded with only some fields (using a field filter) this method will be called to notify
 Object put(int key, Object v)
          Puts a value at an index.
 Object put(String key, Object v)
          Puts a value at an index.
 void putAll(DBObject o)
           
 void putAll(Map m)
           
 Object removeField(String key)
          Remove a field with a given name from this object.
 Map toMap()
          Returns a map representing this DBObject.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, set, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode
 

Constructor Detail

BasicDBList

public BasicDBList()
Method Detail

put

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.

Specified by:
put in interface DBObject
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

put

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

putAll

public void putAll(Map m)
Specified by:
putAll in interface DBObject

putAll

public void putAll(DBObject o)
Specified by:
putAll in interface DBObject

get

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.

Specified by:
get in interface DBObject
Parameters:
key - the index
Returns:
the value, if found, or null
Throws:
IllegalArgumentException - if key cannot be parsed into an int

removeField

public Object removeField(String key)
Description copied from interface: DBObject
Remove a field with a given name from this object.

Specified by:
removeField in interface DBObject
Parameters:
key - The name of the field to remove
Returns:
The value removed from this object

containsKey

public boolean containsKey(String key)
Deprecated. 

Specified by:
containsKey in interface DBObject

containsField

public boolean containsField(String key)
Description copied from interface: DBObject
Checks if this object contains a field with the given name.

Specified by:
containsField in interface DBObject
Parameters:
key - Field name for which to check
Returns:
if this object contains a field with the given name

keySet

public Set<String> keySet()
Description copied from interface: DBObject
Returns this object's fields' names

Specified by:
keySet in interface DBObject
Returns:
The names of the fields in this object

toMap

public Map toMap()
Description copied from interface: DBObject
Returns a map representing this DBObject.

Specified by:
toMap in interface DBObject
Returns:
the map

isPartialObject

public boolean isPartialObject()
Description copied from interface: DBObject
whether markAsPartialObject was ever called only matters if you are going to upsert and dont' want to risk losing fields

Specified by:
isPartialObject in interface DBObject

markAsPartialObject

public void markAsPartialObject()
Description copied from interface: DBObject
if this object was loaded with only some fields (using a field filter) this method will be called to notify

Specified by:
markAsPartialObject in interface DBObject