@Override protected int doReadInt32() { return currentValue.asInt32().getValue(); }
static ServerVersion getVersion(final BsonDocument buildInfoResult) { List<BsonValue> versionArray = buildInfoResult.getArray("versionArray").subList(0, 3); return new ServerVersion(asList(versionArray.get(0).asInt32().getValue(), versionArray.get(1).asInt32().getValue(), versionArray.get(2).asInt32().getValue())); }
/** * Gets the value of the key if it is a BsonInt32, or throws if not. * * @param key the key * @return the value of the key as a BsonInt32 * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonInt32 getInt32(final Object key) { throwIfKeyAbsent(key); return get(key).asInt32(); }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonInt32. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonInt32 * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonInt32 getInt32(final Object key, final BsonInt32 defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asInt32(); }
colValue = keyvalueforStruct.getValue().asInt32().getValue(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.INT32 && valueType == BsonType.INT32) { int temp = arrValue.asInt32().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.INT64 && valueType == BsonType.INT64) { list.add(temp); } else if (arrValue.getBsonType() == BsonType.TIMESTAMP && valueType == BsonType.TIMESTAMP) { int temp = arrValue.asInt32().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.BOOLEAN && valueType == BsonType.BOOLEAN) {
@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.asInt32().getValue(); case INT64: return value.asInt64().getValue();
check(doc.get("boolean").asBoolean()); check(doc.get("int32").getBsonType()).is(BsonType.INT32); check(doc.get("int32").asInt32().getValue()).is(32); check(doc.get("int64").getBsonType()).is(BsonType.INT64); check(doc.get("int64").asInt64().getValue()).is(64L);
break; case INT32: writeInt32(value.asInt32().getValue()); break; case TIMESTAMP:
static ServerVersion getVersion(final BsonDocument buildInfoResult) { List<BsonValue> versionArray = buildInfoResult.getArray("versionArray").subList(0, 3); return new ServerVersion(asList(versionArray.get(0).asInt32().getValue(), versionArray.get(1).asInt32().getValue(), versionArray.get(2).asInt32().getValue())); }
return value.asInt32().getValue(); case INT64: return value.asInt64().getValue();
@Override public Integer getIpProtocolVersion() { return first(get(document, "flows", "0:1", "protocol") .flatMap(v -> { switch (v.asInt32().getValue()) { case 11: return Optional.of(4); case 12: return Optional.of(6); default: return Optional.empty(); } }), get(document, "flows", "0:3").map(v -> 4), get(document, "flows", "0:4").map(v -> 6)) .orElse(null); }
@Override public Long getBytes() { return first(get(document, "flows", "0:3", "length"), get(document, "flows", "0:4", "length"), get(document, "flows", "0:1", "ipv4", "length"), get(document, "flows", "0:1", "ipv6", "length")) .map(v -> (long) v.asInt32().getValue()) .orElse(null); }
@Override public Integer getProtocol() { return first(get(document, "flows", "0:3", "protocol"), get(document, "flows", "0:4", "protocol"), get(document, "flows", "0:1", "ipv4", "protocol"), get(document, "flows", "0:1", "ipv6", "protocol")) .map(v -> v.asInt32().getValue()) .orElse(null); }
@Override public Integer getTos() { return first(get(document, "flows", "0:3", "tos"), get(document, "flows", "0:4", "tos"), get(document, "flows", "0:1", "ipv4", "tos"), get(document, "flows", "0:1", "ipv6", "tos")) .map(v -> v.asInt32().getValue()) .orElse(null); }
@Override public Integer getSrcPort() { return first(get(document, "flows", "0:3", "src_port"), get(document, "flows", "0:4", "src_port"), get(document, "flows", "0:1", "ipv4", "src_port"), get(document, "flows", "0:1", "ipv6", "src_port")) .map(v -> v.asInt32().getValue()) .orElse(null); }
@Override public Integer getDstPort() { return first(get(document, "flows", "0:3", "dst_port"), get(document, "flows", "0:4", "dst_port"), get(document, "flows", "0:1", "ipv4", "dst_port"), get(document, "flows", "0:1", "ipv6", "dst_port")) .map(v -> v.asInt32().getValue()) .orElse(null); }
@Override public Integer getTcpFlags() { return first(get(document, "flows", "0:3", "tcp_flags"), get(document, "flows", "0:4", "tcp_flags"), get(document, "flows", "0:1", "ipv4", "tcp_flags"), get(document, "flows", "0:1", "ipv6", "tcp_flags")) .map(v -> v.asInt32().getValue()) .orElse(null); }
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(); } }
private static BsonDateTime getIdAsDate(String id) throws IllegalArgumentException { BsonValue ret = JsonUtils.parse(id); if (ret.isDateTime()) { return ret.asDateTime(); } else if (ret.isInt32()) { return new BsonDateTime(0l + ret.asInt32().getValue()); } else if (ret.isInt64()) { return new BsonDateTime(ret.asInt64().getValue()); } else { throw new IllegalArgumentException("The id is not a valid number " + id); } }