@Override protected boolean doReadBoolean() { return currentValue.asBoolean().getValue(); }
/** * Gets the value of the key if it is a BsonBoolean, or throws if not. * * @param key the key * @return the value of the key as a BsonBoolean * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonBoolean getBoolean(final Object key) { throwIfKeyAbsent(key); return get(key).asBoolean(); }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonBoolean. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonBoolean * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonBoolean getBoolean(final Object key, final BsonBoolean defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asBoolean(); }
private static boolean isCommandOk(final BsonValue okValue) { if (okValue == null) { return false; } else if (okValue.isBoolean()) { return okValue.asBoolean().getValue(); } else if (okValue.isNumber()) { return okValue.asNumber().intValue() == 1; } else { return false; } }
static boolean isCommandOk(final BsonDocument response) { if (!response.containsKey("ok")) { return false; } BsonValue okValue = response.get("ok"); if (okValue.isBoolean()) { return okValue.asBoolean().getValue(); } else if (okValue.isNumber()) { return okValue.asNumber().intValue() == 1; } else { return false; } }
if (!valueEntry.getValue().asBoolean().getValue()) { continue;
colValue = keyvalueforStruct.getValue().asBoolean().getValue(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.BOOLEAN && valueType == BsonType.BOOLEAN) { boolean temp = arrValue.asBoolean().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DOCUMENT && valueType == BsonType.DOCUMENT) {
@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.asDouble().getValue(); case BOOLEAN: return value.asBoolean().getValue(); case OBJECT_ID: return value.asObjectId().getValue();
check(doc.get("boolean").asBoolean()); check(doc.get("int32").getBsonType()).is(BsonType.INT32); check(doc.get("int32").asInt32().getValue()).is(32);
break; case BOOLEAN: writeBoolean(value.asBoolean().getValue()); break; case DATE_TIME:
return value.asDouble().getValue(); case BOOLEAN: return value.asBoolean().getValue(); case OBJECT_ID: return value.asObjectId().getValue();
private static boolean isCommandOk(final BsonValue okValue) { if (okValue == null) { return false; } else if (okValue.isBoolean()) { return okValue.asBoolean().getValue(); } else if (okValue.isNumber()) { return okValue.asNumber().intValue() == 1; } else { return false; } }
static boolean isCommandOk(final BsonDocument response) { if (!response.containsKey("ok")) { return false; } BsonValue okValue = response.get("ok"); if (okValue.isBoolean()) { return okValue.asBoolean().getValue(); } else if (okValue.isNumber()) { return okValue.asNumber().intValue() == 1; } else { return false; } }
private static JsonValue mapBsonValueToJsonValue(@Nullable final BsonValue bsonValue, final Function<String, String> jsonKeyNameReviser) { final JsonValue result; if (bsonValue == null || bsonValue.isNull()) { result = JsonFactory.nullLiteral(); } else if (bsonValue.isString()) { result = JsonFactory.newValue(bsonValue.asString().getValue()); } else if (bsonValue.isNumber()) { result = mapBsonNumberToJsonNumber(bsonValue.asNumber()); } else if (bsonValue.isDocument()) { result = mapBsonDocumentToJsonObject(bsonValue.asDocument(), jsonKeyNameReviser); } else if (bsonValue.isArray()) { result = mapBsonArrayToJsonArray(bsonValue.asArray(), jsonKeyNameReviser); } else if (bsonValue.isBoolean()) { result = JsonFactory.newValue(bsonValue.asBoolean().getValue()); } else if (bsonValue.isTimestamp()) { final Instant instant = Instant.ofEpochSecond(bsonValue.asTimestamp().getTime()); result = JsonFactory.newValue(instant.toString()); } else { result = JsonFactory.nullLiteral(); } return result; }
@TestFactory @DisplayName("tests for boolean field conversions") public List<DynamicTest> testBooleanFieldConverter() { SinkFieldConverter converter = new BooleanFieldConverter(); List<DynamicTest> tests = new ArrayList<>(); new ArrayList<>(Arrays.asList(true,false)).forEach(el -> { tests.add(dynamicTest("conversion with " + converter.getClass().getSimpleName() + " for "+el, () -> assertEquals(el, ((BsonBoolean)converter.toBson(el)).getValue()) )); }); tests.add(dynamicTest("optional type conversion checks", () -> { Schema valueOptionalDefault = SchemaBuilder.bool().optional().defaultValue(true); assertAll("", () -> assertThrows(DataException.class, () -> converter.toBson(null, Schema.BOOLEAN_SCHEMA)), () -> assertEquals(new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BOOLEAN_SCHEMA)), () -> assertEquals(valueOptionalDefault.defaultValue(), converter.toBson(null, valueOptionalDefault).asBoolean().getValue()) ); })); return tests; }
? _allowDiskUse.asBoolean() : BsonBoolean.FALSE;
+ "' element. it must be boolean"); } else { skipNotSupported = _skipNotSupported.asBoolean().getValue();
boolean bool = value.asBoolean().getValue(); if (bool) { return BooleanValue.TRUE;