org.bson
Class LazyBSONObject

java.lang.Object
  extended by org.bson.LazyBSONObject
All Implemented Interfaces:
BSONObject
Direct Known Subclasses:
KeyCachingLazyBSONObject, LazyBSONList, LazyDBObject

public class LazyBSONObject
extends Object
implements BSONObject

Author:
antoine, brendan, scotthernandez, Kilroy Wuz Here

Nested Class Summary
 class LazyBSONObject.LazyBSONKeySet
           
 
Field Summary
protected  LazyBSONCallback _callback
           
protected  int _doc_start_offset
           
protected  BSONByteBuffer _input
           
 
Constructor Summary
LazyBSONObject(BSONByteBuffer buffer, int offset, LazyBSONCallback callback)
           
LazyBSONObject(BSONByteBuffer buffer, LazyBSONCallback callback)
           
LazyBSONObject(byte[] data, int offset, LazyBSONCallback callback)
           
LazyBSONObject(byte[] data, LazyBSONCallback callback)
           
 
Method Summary
 boolean containsField(String s)
          Checks if this object contains a field with the given name.
 boolean containsKey(String s)
          Deprecated. 
 Set<Map.Entry<String,Object>> entrySet()
          This method will be more efficient than using a combination of keySet() and get(String key)
 boolean equals(Object o)
           
 Object get(String key)
          Gets a field from this object by a given name.
 int getBSONSize()
           
protected  int getElementBSONSize(int offset)
           
protected  byte getElementType(int offset)
           
protected  Object getElementValue(org.bson.LazyBSONObject.ElementRecord record)
           
 int hashCode()
           
protected  boolean isElementEmpty(int offset)
           
 boolean isEmpty()
           
 Set<String> keySet()
          Returns this object's fields' names
 int pipe(OutputStream os)
           
 Object put(String key, Object v)
          Sets a name/value pair in this object.
 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.
protected  int sizeCString(int offset)
          Returns the size of the BSON cstring at the given offset in the buffer
 Map toMap()
          Returns a map representing this BSONObject.
 String toString()
          Returns a JSON serialization of this object
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_doc_start_offset

protected final int _doc_start_offset

_input

protected final BSONByteBuffer _input

_callback

protected final LazyBSONCallback _callback
Constructor Detail

LazyBSONObject

public LazyBSONObject(byte[] data,
                      LazyBSONCallback callback)

LazyBSONObject

public LazyBSONObject(byte[] data,
                      int offset,
                      LazyBSONCallback callback)

LazyBSONObject

public LazyBSONObject(BSONByteBuffer buffer,
                      LazyBSONCallback callback)

LazyBSONObject

public LazyBSONObject(BSONByteBuffer buffer,
                      int offset,
                      LazyBSONCallback callback)
Method Detail

put

public Object put(String key,
                  Object v)
Description copied from interface: BSONObject
Sets a name/value pair in this object.

Specified by:
put in interface BSONObject
Parameters:
key - Name to set
v - Corresponding value
Returns:
v

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

putAll

public void putAll(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

get

public Object get(String key)
Description copied from interface: BSONObject
Gets a field from this object by a given name.

Specified by:
get in interface BSONObject
Parameters:
key - The name of the field fetch
Returns:
The field, if found

toMap

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

Specified by:
toMap in interface BSONObject
Returns:
the map

removeField

public Object removeField(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(String s)
Deprecated. 

Description copied from interface: BSONObject
Deprecated

Specified by:
containsKey in interface BSONObject
Returns:
True if the key is present

containsField

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

Specified by:
containsField in interface BSONObject
Parameters:
s - Field name for which to check
Returns:
True if the field is present

keySet

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

Specified by:
keySet in interface BSONObject
Returns:
the set of all keys in the document

entrySet

public Set<Map.Entry<String,Object>> entrySet()
This method will be more efficient than using a combination of keySet() and get(String key)

Returns:
the set of entries (key, value) in the document

isElementEmpty

protected boolean isElementEmpty(int offset)

isEmpty

public boolean isEmpty()

getBSONSize

public int getBSONSize()

pipe

public int pipe(OutputStream os)
         throws IOException
Throws:
IOException

getElementType

protected byte getElementType(int offset)

getElementBSONSize

protected int getElementBSONSize(int offset)

sizeCString

protected int sizeCString(int offset)
Returns the size of the BSON cstring at the given offset in the buffer

Parameters:
offset - the offset into the buffer
Returns:
the size of the BSON cstring, including the null terminator

getElementValue

protected Object getElementValue(org.bson.LazyBSONObject.ElementRecord record)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Returns a JSON serialization of this object

Overrides:
toString in class Object
Returns:
JSON serialization