com.mongodb
Class BasicDBObjectBuilder

java.lang.Object
  extended by com.mongodb.BasicDBObjectBuilder

public class BasicDBObjectBuilder
extends Object

utility for building complex objects example: BasicDBObjectBuilder.start().add( "name" , "eliot" ).add( "number" , 17 ).get()


Constructor Summary
BasicDBObjectBuilder()
          creates an empty object
 
Method Summary
 BasicDBObjectBuilder add(String key, Object val)
          same as appends
 BasicDBObjectBuilder append(String key, Object val)
          appends the key/value to the active object
 DBObject get()
          gets the base object
 boolean isEmpty()
          returns true if no key/value was inserted into base object
 BasicDBObjectBuilder pop()
          pops the active object, which means that the parent object becomes active
 BasicDBObjectBuilder push(String key)
          creates an new empty object and inserts it into the current object with the given key.
static BasicDBObjectBuilder start()
          Creates an empty object
static BasicDBObjectBuilder start(Map m)
          Creates an object builder from an existing map.
static BasicDBObjectBuilder start(String k, Object val)
          creates an object with the given key/value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicDBObjectBuilder

public BasicDBObjectBuilder()
creates an empty object

Method Detail

start

public static BasicDBObjectBuilder start()
Creates an empty object

Returns:
The new empty builder

start

public static BasicDBObjectBuilder start(String k,
                                         Object val)
creates an object with the given key/value

Parameters:
k - The field name
val - The value

start

public static BasicDBObjectBuilder start(Map m)
Creates an object builder from an existing map.

Parameters:
m - map to use
Returns:
the new builder

append

public BasicDBObjectBuilder append(String key,
                                   Object val)
appends the key/value to the active object

Parameters:
key -
val -
Returns:
returns itself so you can chain

add

public BasicDBObjectBuilder add(String key,
                                Object val)
same as appends

Parameters:
key -
val -
Returns:
returns itself so you can chain
See Also:
append(String, Object)

push

public BasicDBObjectBuilder push(String key)
creates an new empty object and inserts it into the current object with the given key. The new child object becomes the active one.

Parameters:
key -
Returns:
returns itself so you can chain

pop

public BasicDBObjectBuilder pop()
pops the active object, which means that the parent object becomes active

Returns:
returns itself so you can chain

get

public DBObject get()
gets the base object

Returns:
The base object

isEmpty

public boolean isEmpty()
returns true if no key/value was inserted into base object

Returns:
True if empty