private boolean getReturnKey(BsonValue<?> value) { switch (value.getType()) { case BOOLEAN: return ((BsonBoolean) value).getPrimitiveValue(); case UNDEFINED: case NULL: return false; default: return true; } }
private boolean getShowDiskLoc(BsonValue<?> value) { switch (value.getType()) { case BOOLEAN: return ((BsonBoolean) value).getPrimitiveValue(); case UNDEFINED: case NULL: return false; default: return true; } }
private boolean getSnapshot(BsonValue<?> value) { switch (value.getType()) { case BOOLEAN: return ((BsonBoolean) value).getPrimitiveValue(); case UNDEFINED: case NULL: return false; default: return true; } }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } assert obj instanceof BsonMin; return 0; }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } assert obj instanceof BsonMax; return 0; }
private long getMaxScan(BsonValue<?> value) { switch (value.getType()) { case INT32: return ((BsonInt32) value).intValue(); case INT64: return ((BsonInt64) value).longValue(); case DOUBLE: return Math.round(((BsonDouble) value).doubleValue()); default: return -1; } }
public static int getInteger(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue<?> object = entry.getValue(); if (!object.isInt32()) { String foundType = toStringBsonType(object.getType()); throw new TypesMismatchException( fieldId, "integer", object.getType(), "Expected integer type for field " + fieldId + ". Found" + foundType ); } return object.asInt32().intValue(); }
public static double getDouble(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue object = entry.getValue(); if (!object.isDouble()) { String foundType = toStringBsonType(object.getType()); throw new TypesMismatchException( fieldId, "integer", object.getType(), "Expected double type for field " + fieldId + ". Found" + foundType ); } return object.asDouble().doubleValue(); }
public static boolean getBoolean(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue object = entry.getValue(); if (object.isBoolean()) { return object.asBoolean().getValue(); } String foundType = toStringBsonType(object.getType()); throw new TypesMismatchException( fieldId, "boolean", object.getType(), "Expected boolean type for field " + fieldId + ". Found " + foundType ); }
public static long getLong(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue object = entry.getValue(); if (!object.isNumber()) { String foundType = toStringBsonType(object.getType()); throw new TypesMismatchException( fieldId, "integer", object.getType(), "Expected long type for field " + fieldId + ". Found" + foundType ); } return object.asNumber().longValue(); }
@Nonnull public static BsonObjectId getObjectId(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue<?> object = entry.getValue(); if (!object.isObjectId()) { throw new TypesMismatchException(fieldId, "objectId", object.getType()); } return object.asObjectId(); }
@Nonnull public static BsonArray getArray(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue<?> object = entry.getValue(); if (!object.isArray()) { throw new TypesMismatchException(fieldId, BsonType.ARRAY, object.getType()); } return object.asArray(); }
public static boolean getBooleanOrUndefined(Entry<?> entry, String fieldId, boolean defaultValue) throws TypesMismatchException { BsonValue object = entry.getValue(); if (object.isUndefined()) { return defaultValue; } if (object.isBoolean()) { return object.asBoolean().getPrimitiveValue(); } throw new TypesMismatchException( fieldId, BsonType.BOOLEAN, object.getType(), "Expected boolean or undefined type for field " + fieldId + ". Found " + object.getType().toString().toLowerCase(Locale.ROOT) ); }
@Nonnull public static Instant getInstant(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue<?> value = entry.getValue(); if (!value.isDateTime()) { throw new TypesMismatchException( fieldId, "date", value.getType(), "Expected date type for field " + fieldId + ". Found" + value ); } return value.asDateTime().getValue(); }
@Nonnull public static BsonDocument getDocument(Entry<?> entry) throws TypesMismatchException { BsonValue<?> object = entry.getValue(); if (!object.isDocument()) { throw new TypesMismatchException(entry.getKey(), BsonType.DOCUMENT, object.getType()); } return object.asDocument(); }
@Nonnull public static String getString(Entry<?> entry) throws TypesMismatchException { BsonValue object = entry.getValue(); if (!object.isString()) { throw new TypesMismatchException(entry.getKey(), "string", object.getType()); } return object.asString().getValue(); }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } assert obj.isString(); return this.getValue().compareTo(obj.asString().getValue()); }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } assert obj.isTimestamp(); return compareTo(obj.asTimestamp()); }
public static BsonTimestamp getTimestamp(BsonDocument doc, String fieldId) throws NoSuchKeyException, TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { throw new NoSuchKeyException(fieldId); } BsonValue<?> value = entry.getValue(); if (!value.isTimestamp()) { throw new TypesMismatchException(fieldId, "timestamp", value.getType()); } return value.asTimestamp(); }
public static BsonTimestamp getTimestampFromDateTime(Entry<?> entry) throws TypesMismatchException { BsonValue<?> value = entry.getValue(); if (!value.isDateTime()) { throw new TypesMismatchException(entry.getKey(), BsonType.DATETIME, value.getType()); } return TimestampToDateTime.toTimestamp( value.asDateTime(), DefaultBsonValues::newTimestamp); } }