Package org.bson
Class BsonDocumentWrapper<T>
- java.lang.Object
-
- org.bson.BsonValue
-
- org.bson.BsonDocument
-
- org.bson.BsonDocumentWrapper<T>
-
- Type Parameters:
T- the type of the document that is wrapped
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,BsonValue>,Bson
public final class BsonDocumentWrapper<T> extends BsonDocument
ABsonDocumentthat begins its life as a document of any type and anEncoderfor that document, which lets an instance of any class with an Encoder be treated as a BsonDocument. If any methods are called which required access to the individual elements of the document, then, on demand, the document will be unwrapped into a BsonDocument using aBsonDocumentWriterand theEncoder. But if all that is done with this document is to encode it, then theEncoderwill be used to do that.- Since:
- 3.0
- See Also:
BsonDocumentWriter, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BsonDocumentWrapper(T wrappedDocument, Encoder<T> encoder)Construct a new instance with the given document and encoder for the document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BsonDocumentasBsonDocument(java.lang.Object document, CodecRegistry codecRegistry)A helper to convert an document of type Object to a BsonDocumentvoidclear()BsonDocumentclone()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.String,BsonValue>>entrySet()booleanequals(java.lang.Object o)BsonValueget(java.lang.Object key)Encoder<T>getEncoder()Get the encoder to use for the wrapped document.TgetWrappedDocument()Get the wrapped document.inthashCode()booleanisEmpty()booleanisUnwrapped()Determine whether the document has been unwrapped already.java.util.Set<java.lang.String>keySet()BsonValueput(java.lang.String key, BsonValue value)voidputAll(java.util.Map<? extends java.lang.String,? extends BsonValue> m)BsonValueremove(java.lang.Object key)intsize()java.lang.StringtoString()java.util.Collection<BsonValue>values()-
Methods inherited from class org.bson.BsonDocument
append, asBsonReader, get, getArray, getArray, getBinary, getBinary, getBoolean, getBoolean, getBsonType, getDateTime, getDateTime, getDecimal128, getDecimal128, getDocument, getDocument, getDouble, getDouble, getFirstKey, getInt32, getInt32, getInt64, getInt64, getNumber, getNumber, getObjectId, getObjectId, getRegularExpression, getRegularExpression, getString, getString, getTimestamp, getTimestamp, isArray, isBinary, isBoolean, isDateTime, isDecimal128, isDocument, isDouble, isInt32, isInt64, isNull, isNumber, isObjectId, isString, isTimestamp, parse, toBsonDocument, toJson, toJson
-
Methods inherited from class org.bson.BsonValue
asArray, asBinary, asBoolean, asDateTime, asDBPointer, asDecimal128, asDocument, asDouble, asInt32, asInt64, asJavaScript, asJavaScriptWithScope, asNumber, asObjectId, asRegularExpression, asString, asSymbol, asTimestamp, isArray, isBinary, isBoolean, isDateTime, isDBPointer, isDecimal128, isDocument, isDouble, isInt32, isInt64, isJavaScript, isJavaScriptWithScope, isNull, isNumber, isObjectId, isRegularExpression, isString, isSymbol, isTimestamp
-
-
-
-
Method Detail
-
asBsonDocument
public static BsonDocument asBsonDocument(java.lang.Object document, CodecRegistry codecRegistry)
A helper to convert an document of type Object to a BsonDocumentIf not already a BsonDocument it looks up the documents' class in the codecRegistry and wraps it into a BsonDocumentWrapper
- Parameters:
document- the document to convertcodecRegistry- the codecRegistry that can be used in the conversion of the Object- Returns:
- a BsonDocument
-
getWrappedDocument
public T getWrappedDocument()
Get the wrapped document.- Returns:
- the wrapped document
-
getEncoder
public Encoder<T> getEncoder()
Get the encoder to use for the wrapped document.- Returns:
- the encoder
-
isUnwrapped
public boolean isUnwrapped()
Determine whether the document has been unwrapped already.- Returns:
- true if the wrapped document has been unwrapped already
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
sizein classBsonDocument
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
isEmptyin classBsonDocument
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
containsKeyin classBsonDocument
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
containsValuein classBsonDocument
-
get
public BsonValue get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
getin classBsonDocument
-
put
public BsonValue put(java.lang.String key, BsonValue value)
- Specified by:
putin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
putin classBsonDocument
-
remove
public BsonValue remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
removein classBsonDocument
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,? extends BsonValue> m)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
putAllin classBsonDocument
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
clearin classBsonDocument
-
keySet
public java.util.Set<java.lang.String> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
keySetin classBsonDocument
-
values
public java.util.Collection<BsonValue> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
valuesin classBsonDocument
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,BsonValue>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
entrySetin classBsonDocument
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
equalsin classBsonDocument
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map<java.lang.String,BsonValue>- Overrides:
hashCodein classBsonDocument
-
toString
public java.lang.String toString()
- Overrides:
toStringin classBsonDocument
-
clone
public BsonDocument clone()
- Overrides:
clonein classBsonDocument
-
-