@Nonnull public static HostAndPort getHostAndPort(Entry<?> entry) throws TypesMismatchException { String string = getString(entry); return getHostAndPort(string); }
/** * Confirms that the given bson object only contains fields whose names given. * * @param objectName the container's name, that will be included in the error messages * @param bson the object whose fields are going to be checked * @param fields the fields we are going to accept * @throws BadValueException if an unexpected field is found */ public static void checkOnlyHasFields( String objectName, BsonDocument bson, String... fields) throws BadValueException { checkOnlyHasFields(objectName, bson, Sets.newHashSet(fields)); }
public static boolean getBoolean(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getBoolean(getEntry(doc, fieldId), fieldId); }
@Nullable public static String getString(BsonDocument doc, StringField field, String defaultValue) throws TypesMismatchException { return getString(doc, field.getFieldName(), defaultValue); }
public static BsonTimestamp getTimestampFromDateTime(BsonDocument doc, DateTimeField field) throws NoSuchKeyException, TypesMismatchException { return getTimestampFromDateTime(getEntry(doc, field)); }
@Nonnull public static BsonDocument getDocument(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getDocument(getEntry(doc, fieldId)); }
@Nonnull public static Instant getInstant(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getInstant(getEntry(doc, fieldId), fieldId); }
@Nonnull public static BsonNumber<?> getNumeric(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getNumeric(getEntry(doc, fieldId), fieldId); }
@Nonnull public static HostAndPort getHostAndPort(BsonDocument doc, String fieldName) throws TypesMismatchException, NoSuchKeyException { return getHostAndPort(getEntry(doc, fieldName)); }
@Nonnull public static BsonObjectId getObjectId(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getObjectId(getEntry(doc, fieldId), fieldId); }
j = BsonReaderTool.getBooleanOrNumeric(doc, "j", false); } catch (TypesMismatchException ex) { throw new FailedToParseException("j must be numeric or boolean value"); fsync = BsonReaderTool.getBooleanOrNumeric(doc, "fsync", false); } catch (TypesMismatchException ex) { throw new FailedToParseException("fsync must be numeric or a boolean value"); timeout = BsonReaderTool.getNumeric(doc, "timeout").intValue(); } catch (NoSuchKeyException ex) { timeout = 0;
@Nullable public static BsonArray getArray(BsonDocument doc, String fieldId, BsonArray defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getArray(entry, fieldId); }
public static double getDouble(BsonDocument doc, String fieldId, double defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getDouble(entry, fieldId); }
@Nonnull public static boolean getBoolean(Entry<?> entry, BooleanField field) throws TypesMismatchException { return getBoolean(entry, field.getFieldName()); }
@Nullable public static BsonDocument getDocument(BsonDocument doc, DocField field, BsonDocument defaultValue) throws TypesMismatchException { return getDocument(doc, field.getFieldName(), defaultValue); }
public static boolean getBooleanOrNumeric(BsonDocument doc, String fieldId, boolean defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getBooleanOrNumeric(entry, fieldId); }