@Nullable public static Entry<?> getEntry(BsonDocument doc, String fieldId, Entry<?> defaultValue) { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return entry; }
public default Optional<Entry<?>> getOptionalEntry(String key) { return Optional.ofNullable(getEntry(key)); }
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); }
@Nullable public static BsonNumber<?> getNumeric(BsonDocument doc, String fieldId, BsonNumber defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getNumeric(entry, fieldId); }
@Nullable public static String getString(BsonDocument doc, String fieldId, String defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getString(entry); }
@Nullable public static BsonObjectId getObjectId(BsonDocument doc, String fieldId, BsonObjectId defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getObjectId(entry, fieldId); }
@Nonnull public static Entry<?> getEntry(BsonDocument doc, String fieldId) throws NoSuchKeyException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { throw new NoSuchKeyException(fieldId); } return entry; }
@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 long getLong(BsonDocument doc, String fieldId, long defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getLong(entry, fieldId); }
@Nullable public static BsonDocument getDocument(BsonDocument doc, String fieldId, BsonDocument defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getDocument(entry); }
public static int getInteger(BsonDocument doc, String fieldId, int defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getInteger(entry, fieldId); }
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); }
public static boolean getBoolean(BsonDocument doc, String fieldId, boolean defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getBoolean(entry, fieldId); }
@Nullable public static Instant getInstant(BsonDocument doc, String fieldId, Instant defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getInstant(entry, fieldId); }
public static boolean getBooleanOrUndefined(BsonDocument doc, String fieldId, boolean defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getBooleanOrUndefined(entry, fieldId, defaultValue); }
@Nullable public static HostAndPort getHostAndPort(BsonDocument doc, String fieldId, HostAndPort defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getHostAndPort(entry); }
public static int getInteger(BsonDocument doc, String fieldId) throws TypesMismatchException, NoSuchKeyException { return getInteger(doc.getEntry(fieldId), fieldId); }
public static boolean isPseudoTrue(BsonDocument doc, String fieldId) { return isPseudoTrue(doc.getEntry(fieldId)); }
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(); }