@Nonnull public static BsonNumber<?> getNumeric(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue<?> object = entry.getValue(); if (!object.isNumber()) { String foundType = object.getType().toString().toLowerCase(Locale.ROOT); throw new TypesMismatchException( fieldId, "numeric", object.getType(), fieldId + " field has non-numeric type " + foundType ); } return object.asNumber(); }
@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 BsonNumber; BsonNumber<?> other = obj.asNumber(); return Doubles.compare(this.doubleValue(), other.doubleValue()); }
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(); }
public static boolean getBooleanOrNumeric(Entry<?> entry, String fieldId) throws TypesMismatchException { BsonValue object = entry.getValue(); if (object.isNumber()) { return object.asNumber().intValue() != 0; } if (object.isBoolean()) { return object.asBoolean().getPrimitiveValue(); } throw new TypesMismatchException( fieldId, BsonType.BOOLEAN, object.getType(), "Expected boolean or numeric type for field " + fieldId + ". Found " + object.getType().toString().toLowerCase(Locale.ROOT) ); }
return new IntWriteConcern(syncMode, timeout, wValue.asNumber().intValue());