作者:张俊凯宜珮 | 来源:互联网 | 2023-09-18 13:19
本文整理了Java中org.bson.BsonValue.asDecimal128()
方法的一些代码示例,展示了BsonValue.asDecimal128()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BsonValue.asDecimal128()
方法的具体详情如下:
包路径:org.bson.BsonValue
类名称:BsonValue
方法名:asDecimal128
BsonValue.asDecimal128介绍
[英]Gets this value as a BsonDecimal128 if it is one, otherwise throws exception
[中]如果此值为BsonDecimal128,则将其作为BsonDecimal128获取,否则将引发异常
代码示例
代码示例来源:origin: org.mongodb/mongo-java-driver
@Override
public Decimal128 doReadDecimal128() {
return currentValue.asDecimal128().getValue();
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Gets the value of the key if it is a BsonDecimal128, or throws if not.
*
* @param key the key
* @return the value of the key as a BsonDecimal128
* @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type
* @since 3.4
*/
public BsonDecimal128 getDecimal128(final Object key) {
throwIfKeyAbsent(key);
return get(key).asDecimal128();
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a
* BsonDecimal128.
*
* @param key the key
* @param defaultValue the default value
* @return the value of the key as a BsonDecimal128
* @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type
* @since 3.4
*/
public BsonDecimal128 getDecimal128(final Object key, final BsonDecimal128 defaultValue) {
if (!containsKey(key)) {
return defaultValue;
}
return get(key).asDecimal128();
}
代码示例来源:origin: immutables/immutables
@Test
public void write() throws Exception {
JsonObject obj = new JsonObject();
BigInteger bigInteger = new BigInteger(Long.toString(Long.MAX_VALUE)).multiply(new BigInteger("128"));
obj.addProperty("bigInteger", bigInteger);
BigDecimal bigDecimal = new BigDecimal(Long.MAX_VALUE).multiply(new BigDecimal(1024));
obj.addProperty("bigDecimal", bigDecimal);
BsonDocument doc = Jsons.toBson(obj);
check(doc.get("bigInteger").getBsonType()).is(BsonType.DECIMAL128);
check(doc.get("bigInteger").asDecimal128().decimal128Value().bigDecimalValue().toBigInteger()).is(bigInteger);
check(doc.get("bigDecimal").getBsonType()).is(BsonType.DECIMAL128);
check(doc.get("bigDecimal").asDecimal128().decimal128Value().bigDecimalValue()).is(bigDecimal);
}
代码示例来源:origin: immutables/immutables
@Test
public void bigNumbers() throws Exception {
JsonObject obj = new JsonObject();
BigInteger bigInteger = new BigInteger(Long.toString(Long.MAX_VALUE)).multiply(new BigInteger("128"));
obj.addProperty("bigInteger", bigInteger);
BigDecimal bigDecimal = new BigDecimal(Long.MAX_VALUE).multiply(new BigDecimal(1024));
obj.addProperty("bigDecimal", bigDecimal);
BsonDocument bson = Jsons.toBson(obj);
check(bson.get("bigInteger").getBsonType()).is(BsonType.DECIMAL128);
check(bson.get("bigInteger").asDecimal128().decimal128Value().bigDecimalValue().toBigInteger()).is(bigInteger);
check(bson.get("bigDecimal").getBsonType()).is(BsonType.DECIMAL128);
check(bson.get("bigDecimal").asDecimal128().decimal128Value().bigDecimalValue()).is(bigDecimal);
check(Jsons.toGson(bson)).is(obj);
}
}
代码示例来源:origin: debezium/debezium
colValue = keyvalueforStruct.getValue().asDecimal128().getValue().toString();
break;
list.add(temp);
} else if (arrValue.getBsonType() == BsonType.DECIMAL128 && valueType == BsonType.DECIMAL128) {
String temp = arrValue.asDecimal128().getValue().toString();
list.add(temp);
} else if (arrValue.getBsonType() == BsonType.TIMESTAMP && valueType == BsonType.TIMESTAMP) {
代码示例来源:origin: spring-projects/spring-data-mongodb
return value.asString().getValue();
case DECIMAL128:
return value.asDecimal128().doubleValue();
case DOUBLE:
return value.asDouble().getValue();
代码示例来源:origin: org.mongodb/mongo-java-driver
break;
case DECIMAL128:
writeDecimal128(value.asDecimal128().getValue());
break;
case MIN_KEY:
代码示例来源:origin: org.springframework.data/spring-data-mongodb
return value.asString().getValue();
case DECIMAL128:
return value.asDecimal128().doubleValue();
case DOUBLE:
return value.asDouble().getValue();
代码示例来源:origin: mongojack/mongojack
public static Object extractValueEx(BsonValue value) {
switch (value.getBsonType()) {
case DOUBLE:
return value.asDouble().getValue();
case STRING:
return value.asString().getValue();
case OBJECT_ID:
return value.asObjectId().getValue();
case INT32:
return value.asInt32().getValue();
case INT64:
return value.asInt64().getValue();
case DECIMAL128:
return value.asDecimal128().getValue();
case NULL:
return null;
}
throw new IllegalArgumentException("Unsupported ID type: " + value.getClass());
}
代码示例来源:origin: com.torodb.mongowp.bson/org-bson-utils
value.asDecimal128().decimal128Value().getHigh(),
value.asDecimal128().decimal128Value().getLow());
case Javascript_WITH_SCOPE: {
BsonJavascriptWithScope casted = value.asJavascriptWithScope();