@Override public Decimal128 doReadDecimal128() { return currentValue.asDecimal128().getValue(); }
/** * 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(); }
/** * 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(); }
@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); }
@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); } }
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) {
return value.asString().getValue(); case DECIMAL128: return value.asDecimal128().doubleValue(); case DOUBLE: return value.asDouble().getValue();
break; case DECIMAL128: writeDecimal128(value.asDecimal128().getValue()); break; case MIN_KEY:
return value.asString().getValue(); case DECIMAL128: return value.asDecimal128().doubleValue(); case DOUBLE: return value.asDouble().getValue();
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()); }
value.asDecimal128().decimal128Value().getHigh(), value.asDecimal128().decimal128Value().getLow()); case JAVASCRIPT_WITH_SCOPE: { BsonJavaScriptWithScope casted = value.asJavaScriptWithScope();