@Override protected double doReadDouble() { return currentValue.asDouble().getValue(); }
/** * Gets the value of the key if it is a BsonDouble, or throws if not. * * @param key the key * @return the value of the key as a BsonDouble * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonDouble getDouble(final Object key) { throwIfKeyAbsent(key); return get(key).asDouble(); }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonDouble. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonDouble * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonDouble getDouble(final Object key, final BsonDouble defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asDouble(); }
colValue = keyvalueforStruct.getValue().asDouble().getValue(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.DOUBLE && valueType == BsonType.DOUBLE) { double temp = arrValue.asDouble().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.BINARY && valueType == BsonType.BINARY) {
@Test public void basicNumbers() throws Exception { JsonObject obj = new JsonObject(); obj.addProperty("boolean", true); obj.addProperty("byte", (byte) 1); obj.addProperty("short", (short) 4); obj.addProperty("int", Integer.MAX_VALUE); obj.addProperty("long", Long.MAX_VALUE); obj.addProperty("float", 55F); obj.addProperty("double", 128D); BsonDocument doc = Jsons.toBson(obj); check(doc.get("boolean").getBsonType()).is(BsonType.BOOLEAN); check(doc.get("boolean").asBoolean()); check(doc.get("byte").getBsonType()).is(BsonType.INT32); check(doc.get("byte").asInt32().getValue()).is(1); check(doc.get("short").getBsonType()).is(BsonType.INT32); check(doc.get("short").asInt32().getValue()).is(4); check(doc.get("int").getBsonType()).is(BsonType.INT32); check(doc.get("int").asInt32().getValue()).is(Integer.MAX_VALUE); check(doc.get("long").getBsonType()).is(BsonType.INT64); check(doc.get("long").asInt64().getValue()).is(Long.MAX_VALUE); check(doc.get("float").getBsonType()).is(BsonType.DOUBLE); check(doc.get("float").asDouble().getValue()).is(55D); check(doc.get("double").getBsonType()).is(BsonType.DOUBLE); check(doc.get("double").asDouble().getValue()).is(128D); }
return value.asDecimal128().doubleValue(); case DOUBLE: return value.asDouble().getValue(); case BOOLEAN: return value.asBoolean().getValue();
check(doc.get("int64").asInt64().getValue()).is(64L); check(doc.get("double").getBsonType()).is(BsonType.DOUBLE); check(doc.get("double").asDouble().getValue()).is(42.42D); check(doc.get("string").getBsonType()).is(BsonType.STRING); check(doc.get("string").asString().getValue()).is("foo");
break; case DOUBLE: writeDouble(value.asDouble().getValue()); break; case STRING:
return value.asDecimal128().doubleValue(); case DOUBLE: return value.asDouble().getValue(); case BOOLEAN: return value.asBoolean().getValue();
private String valueAsString(BsonValue value) { if (value.isDouble()) { return Double.toString(value.asDouble().getValue()); } else if (value.isString()) { return value.asString().getValue(); } else if (value.isInt64()) { return Long.toString(value.asInt64().getValue()); } else if (value.isInt32()) { return Long.toString(value.asInt32().getValue()); } else { return value.toString(); } }
uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/") .concat("" + docId.asDouble().getValue()) .concat("?") .concat(DOC_ID_TYPE_QPARAM_KEY)
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()); }
return PrimitiveBsonDouble.newInstance(value.asDouble().getValue()); case BOOLEAN: if (value.asBoolean().getValue()) {
return PrimitiveBsonDouble.newInstance(value.asDouble().getValue()); case BOOLEAN: if (value.asBoolean().getValue()) {
return new DoubleValue(value.asDouble().getValue());