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
public final class BsonDocumentWrapper<T> extends BsonDocument
ABsonDocument
that begins its life as a document of any type and anEncoder
for 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 aBsonDocumentWriter
and theEncoder
. But if all that is done with this document is to encode it, then theEncoder
will 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 BsonDocument
asBsonDocument(Object document, CodecRegistry codecRegistry)
A helper to convert an document of type Object to a BsonDocumentvoid
clear()
BsonDocument
clone()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<String,BsonValue>>
entrySet()
boolean
equals(Object o)
BsonValue
get(Object key)
Encoder<T>
getEncoder()
Get the encoder to use for the wrapped document.T
getWrappedDocument()
Get the wrapped document.int
hashCode()
boolean
isEmpty()
boolean
isUnwrapped()
Determine whether the document has been unwrapped already.Set<String>
keySet()
BsonValue
put(String key, BsonValue value)
void
putAll(Map<? extends String,? extends BsonValue> m)
BsonValue
remove(Object key)
int
size()
String
toString()
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
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, entry, forEach, getOrDefault, merge, of, of, of, of, of, of, of, of, of, of, of, ofEntries, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
asBsonDocument
public static BsonDocument asBsonDocument(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()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<String,BsonValue>
- Overrides:
containsKey
in classBsonDocument
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<String,BsonValue>
- Overrides:
containsValue
in classBsonDocument
-
clear
public void clear()
-
values
public Collection<BsonValue> values()
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
toString
public String toString()
- Overrides:
toString
in classBsonDocument
-
clone
public BsonDocument clone()
- Overrides:
clone
in classBsonDocument
-
-