Package org.bson
Class BsonValue
- java.lang.Object
-
- org.bson.BsonValue
-
- Direct Known Subclasses:
BsonArray,BsonBinary,BsonBoolean,BsonDateTime,BsonDbPointer,BsonDocument,BsonJavaScript,BsonJavaScriptWithScope,BsonMaxKey,BsonMinKey,BsonNull,BsonNumber,BsonObjectId,BsonRegularExpression,BsonString,BsonSymbol,BsonTimestamp,BsonUndefined
public abstract class BsonValue extends Object
Base class for any BSON type.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BsonArrayasArray()Gets this value as a BsonArray if it is one, otherwise throws exceptionBsonBinaryasBinary()Gets this value as a BsonBinary if it is one, otherwise throws exceptionBsonBooleanasBoolean()Gets this value as a BsonBoolean if it is one, otherwise throws exceptionBsonDateTimeasDateTime()Gets this value as a BsonDateTime if it is one, otherwise throws exceptionBsonDbPointerasDBPointer()Gets this value as a BsonDbPointer if it is one, otherwise throws exceptionBsonDecimal128asDecimal128()Gets this value as a BsonDecimal128 if it is one, otherwise throws exceptionBsonDocumentasDocument()Gets this value as a BsonDocument if it is one, otherwise throws exceptionBsonDoubleasDouble()Gets this value as a BsonDouble if it is one, otherwise throws exceptionBsonInt32asInt32()Gets this value as a BsonInt32 if it is one, otherwise throws exceptionBsonInt64asInt64()Gets this value as a BsonInt64 if it is one, otherwise throws exceptionBsonJavaScriptasJavaScript()Gets this value as aBsonJavaScriptif it is one, otherwise throws exceptionBsonJavaScriptWithScopeasJavaScriptWithScope()Gets this value as a BsonJavaScriptWithScope if it is one, otherwise throws exceptionBsonNumberasNumber()Gets this value as a BsonNumber if it is one, otherwise throws exceptionBsonObjectIdasObjectId()Gets this value as an BsonObjectId if it is one, otherwise throws exceptionBsonRegularExpressionasRegularExpression()Gets this value as a BsonRegularExpression if it is one, otherwise throws exceptionBsonStringasString()Gets this value as a BsonString if it is one, otherwise throws exceptionBsonSymbolasSymbol()Gets this value as a BsonSymbol if it is one, otherwise throws exceptionBsonTimestampasTimestamp()Gets this value as a BsonTimestamp if it is one, otherwise throws exceptionabstract BsonTypegetBsonType()Gets the BSON type of this value.booleanisArray()Returns true if this is a BsonArray, false otherwise.booleanisBinary()Returns true if this is a BsonBinary, false otherwise.booleanisBoolean()Returns true if this is a BsonBoolean, false otherwise.booleanisDateTime()Returns true if this is a BsonDateTime, false otherwise.booleanisDBPointer()Returns true if this is a BsonDbPointer, false otherwise.booleanisDecimal128()Returns true if this is a BsonDecimal128, false otherwise.booleanisDocument()Returns true if this is a BsonDocument, false otherwise.booleanisDouble()Returns true if this is a BsonDouble, false otherwise.booleanisInt32()Returns true if this is a BsonInt32, false otherwise.booleanisInt64()Returns true if this is a BsonInt64, false otherwise.booleanisJavaScript()Returns true if this is a BsonJavaScript, false otherwise.booleanisJavaScriptWithScope()Returns true if this is a BsonJavaScriptWithScope, false otherwise.booleanisNull()Returns true if this is a BsonNull, false otherwise.booleanisNumber()Returns true if this is a BsonNumber, false otherwise.booleanisObjectId()Returns true if this is an BsonObjectId, false otherwise.booleanisRegularExpression()Returns true if this is a BsonRegularExpression, false otherwise.booleanisString()Returns true if this is a BsonString, false otherwise.booleanisSymbol()Returns true if this is a BsonSymbol, false otherwise.booleanisTimestamp()Returns true if this is a BsonTimestamp, false otherwise.
-
-
-
Method Detail
-
getBsonType
public abstract BsonType getBsonType()
Gets the BSON type of this value.- Returns:
- the BSON type, which may not be null (but may be BSONType.NULL)
-
asDocument
public BsonDocument asDocument()
Gets this value as a BsonDocument if it is one, otherwise throws exception- Returns:
- a BsonDocument
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asArray
public BsonArray asArray()
Gets this value as a BsonArray if it is one, otherwise throws exception- Returns:
- a BsonArray
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asString
public BsonString asString()
Gets this value as a BsonString if it is one, otherwise throws exception- Returns:
- a BsonString
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asNumber
public BsonNumber asNumber()
Gets this value as a BsonNumber if it is one, otherwise throws exception- Returns:
- a BsonNumber
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asInt32
public BsonInt32 asInt32()
Gets this value as a BsonInt32 if it is one, otherwise throws exception- Returns:
- a BsonInt32
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asInt64
public BsonInt64 asInt64()
Gets this value as a BsonInt64 if it is one, otherwise throws exception- Returns:
- a BsonInt64
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asDecimal128
public BsonDecimal128 asDecimal128()
Gets this value as a BsonDecimal128 if it is one, otherwise throws exception- Returns:
- a BsonDecimal128
- Throws:
BsonInvalidOperationException- if this value is not of the expected type- Since:
- 3.4
-
asDouble
public BsonDouble asDouble()
Gets this value as a BsonDouble if it is one, otherwise throws exception- Returns:
- a BsonDouble
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asBoolean
public BsonBoolean asBoolean()
Gets this value as a BsonBoolean if it is one, otherwise throws exception- Returns:
- a BsonBoolean
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asObjectId
public BsonObjectId asObjectId()
Gets this value as an BsonObjectId if it is one, otherwise throws exception- Returns:
- an BsonObjectId
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asDBPointer
public BsonDbPointer asDBPointer()
Gets this value as a BsonDbPointer if it is one, otherwise throws exception- Returns:
- an BsonDbPointer
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asTimestamp
public BsonTimestamp asTimestamp()
Gets this value as a BsonTimestamp if it is one, otherwise throws exception- Returns:
- an BsonTimestamp
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asBinary
public BsonBinary asBinary()
Gets this value as a BsonBinary if it is one, otherwise throws exception- Returns:
- an BsonBinary
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asDateTime
public BsonDateTime asDateTime()
Gets this value as a BsonDateTime if it is one, otherwise throws exception- Returns:
- an BsonDateTime
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asSymbol
public BsonSymbol asSymbol()
Gets this value as a BsonSymbol if it is one, otherwise throws exception- Returns:
- an BsonSymbol
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asRegularExpression
public BsonRegularExpression asRegularExpression()
Gets this value as a BsonRegularExpression if it is one, otherwise throws exception- Returns:
- an BsonRegularExpression
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asJavaScript
public BsonJavaScript asJavaScript()
Gets this value as aBsonJavaScriptif it is one, otherwise throws exception- Returns:
- a BsonJavaScript
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
asJavaScriptWithScope
public BsonJavaScriptWithScope asJavaScriptWithScope()
Gets this value as a BsonJavaScriptWithScope if it is one, otherwise throws exception- Returns:
- a BsonJavaScriptWithScope
- Throws:
BsonInvalidOperationException- if this value is not of the expected type
-
isNull
public boolean isNull()
Returns true if this is a BsonNull, false otherwise.- Returns:
- true if this is a BsonNull, false otherwise
-
isDocument
public boolean isDocument()
Returns true if this is a BsonDocument, false otherwise.- Returns:
- true if this is a BsonDocument, false otherwise
-
isArray
public boolean isArray()
Returns true if this is a BsonArray, false otherwise.- Returns:
- true if this is a BsonArray, false otherwise
-
isString
public boolean isString()
Returns true if this is a BsonString, false otherwise.- Returns:
- true if this is a BsonString, false otherwise
-
isNumber
public boolean isNumber()
Returns true if this is a BsonNumber, false otherwise.- Returns:
- true if this is a BsonNumber, false otherwise
-
isInt32
public boolean isInt32()
Returns true if this is a BsonInt32, false otherwise.- Returns:
- true if this is a BsonInt32, false otherwise
-
isInt64
public boolean isInt64()
Returns true if this is a BsonInt64, false otherwise.- Returns:
- true if this is a BsonInt64, false otherwise
-
isDecimal128
public boolean isDecimal128()
Returns true if this is a BsonDecimal128, false otherwise.- Returns:
- true if this is a BsonDecimal128, false otherwise
- Since:
- 3.4
-
isDouble
public boolean isDouble()
Returns true if this is a BsonDouble, false otherwise.- Returns:
- true if this is a BsonDouble, false otherwise
-
isBoolean
public boolean isBoolean()
Returns true if this is a BsonBoolean, false otherwise.- Returns:
- true if this is a BsonBoolean, false otherwise
-
isObjectId
public boolean isObjectId()
Returns true if this is an BsonObjectId, false otherwise.- Returns:
- true if this is an BsonObjectId, false otherwise
-
isDBPointer
public boolean isDBPointer()
Returns true if this is a BsonDbPointer, false otherwise.- Returns:
- true if this is a BsonDbPointer, false otherwise
-
isTimestamp
public boolean isTimestamp()
Returns true if this is a BsonTimestamp, false otherwise.- Returns:
- true if this is a BsonTimestamp, false otherwise
-
isBinary
public boolean isBinary()
Returns true if this is a BsonBinary, false otherwise.- Returns:
- true if this is a BsonBinary, false otherwise
-
isDateTime
public boolean isDateTime()
Returns true if this is a BsonDateTime, false otherwise.- Returns:
- true if this is a BsonDateTime, false otherwise
-
isSymbol
public boolean isSymbol()
Returns true if this is a BsonSymbol, false otherwise.- Returns:
- true if this is a BsonSymbol, false otherwise
-
isRegularExpression
public boolean isRegularExpression()
Returns true if this is a BsonRegularExpression, false otherwise.- Returns:
- true if this is a BsonRegularExpression, false otherwise
-
isJavaScript
public boolean isJavaScript()
Returns true if this is a BsonJavaScript, false otherwise.- Returns:
- true if this is a BsonJavaScript, false otherwise
-
isJavaScriptWithScope
public boolean isJavaScriptWithScope()
Returns true if this is a BsonJavaScriptWithScope, false otherwise.- Returns:
- true if this is a BsonJavaScriptWithScope, false otherwise
-
-