@Override protected long doReadInt64() { return currentValue.asInt64().getValue(); }
/** * Gets the value of the key if it is a BsonInt64, or throws if not. * * @param key the key * @return the value of the key as a BsonInt64 * @throws org.bson.BsonInvalidOperationException if the document does not contain the key or the value is not of the expected type */ public BsonInt64 getInt64(final Object key) { throwIfKeyAbsent(key); return get(key).asInt64(); }
/** * If the document does not contain the given key, return the given default value. Otherwise, gets the value of the key as a * BsonInt64. * * @param key the key * @param defaultValue the default value * @return the value of the key as a BsonInt64 * @throws org.bson.BsonInvalidOperationException if the document contains the key but the value is not of the expected type */ public BsonInt64 getInt64(final Object key, final BsonInt64 defaultValue) { if (!containsKey(key)) { return defaultValue; } return get(key).asInt64(); }
colValue = keyvalueforStruct.getValue().asInt64().getValue(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.INT64 && valueType == BsonType.INT64) { long temp = arrValue.asInt64().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DATE_TIME && valueType == BsonType.DATE_TIME) { long temp = arrValue.asInt64().getValue(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.DECIMAL128 && valueType == BsonType.DECIMAL128) {
return value.asInt32().getValue(); case INT64: return value.asInt64().getValue(); case STRING: return value.asString().getValue();
@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); }
check(doc.get("int32").asInt32().getValue()).is(32); check(doc.get("int64").getBsonType()).is(BsonType.INT64); 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);
break; case INT64: writeInt64(value.asInt64().getValue()); break; case DECIMAL128:
public Long getTimestamp() { return BsonUtils.get(document, "time") .map(v -> v.asInt64().getValue()) .orElse(null); }
public Long getSequenceNumber() { return get(document, "sequence_number") .map(v -> v.asInt64().getValue()) .orElse(0L); } }
public Integer getSubAgentId() { return get(document, "sub_agent_id") .map(v -> (int) v.asInt64().getValue()) .orElse(null); }
@Override public Integer getSrcAs() { return get(document, "flows", "0:1003", "src_as") .map(v -> (int) v.asInt64().getValue()) .orElse(null); }
@Override public Double getSamplingInterval() { return get(document, "sampling_rate") .map(v -> (double) v.asInt64().getValue()) .orElse(null); }
@Override public Integer getSrcMaskLen() { return get(document, "flows", "0:1002", "src_mask_len") .map(v -> (int) v.asInt64().getValue()) .orElse(null); }
@Override public Integer getDstMaskLen() { return get(document, "flows", "0:1002", "dst_mask_len") .map(v -> (int) v.asInt64().getValue()) .orElse(null); }
return value.asInt32().getValue(); case INT64: return value.asInt64().getValue(); case STRING: return value.asString().getValue();
@Override public Integer getVlan() { return first(get(document, "flows", "0:1001", "src_vlan"), get(document, "flows", "0:1", "ethernet", "vlan")) .map(v -> (int) v.asInt64().getValue()) .orElse(null); } }
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); } }