private void throwIfKeyAbsent(final Object key) { if (!containsKey(key)) { throw new BsonInvalidOperationException("Document does not contain key " + key); } }
private boolean keysIntersect(final BsonDocument first, final BsonDocument second) { for (String name : first.keySet()) { if (second.containsKey(name)) { return true; } } return false; }
private static String getString(final BsonDocument response, final String key) { if (response.containsKey(key)) { return response.getString(key).getValue(); } else { return null; } }
/** * Returns true if the value of the key is a BsonArray, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonArray, returns false if the document does not contain the key. */ public boolean isArray(final Object key) { if (!containsKey(key)) { return false; } return get(key).isArray(); }
/** * Returns true if the value of the key is a BsonObjectId, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonObjectId, returns false if the document does not contain the key. */ public boolean isObjectId(final Object key) { if (!containsKey(key)) { return false; } return get(key).isObjectId(); }
/** * Returns true if the value of the key is a BsonDocument, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonDocument, returns false if the document does not contain the key. */ public boolean isDocument(final Object key) { if (!containsKey(key)) { return false; } return get(key).isDocument(); }
/** * Returns true if the value of the key is a BsonDouble, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonDouble, returns false if the document does not contain the key. */ public boolean isDouble(final Object key) { if (!containsKey(key)) { return false; } return get(key).isDouble(); }
/** * Returns true if the value of the key is a BsonString, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonString, returns false if the document does not contain the key. */ public boolean isString(final Object key) { if (!containsKey(key)) { return false; } return get(key).isString(); }
/** * Returns true if the value of the key is a BsonDateTime, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonDateTime, returns false if the document does not contain the key. */ public boolean isDateTime(final Object key) { if (!containsKey(key)) { return false; } return get(key).isDateTime(); }
/** * Returns true if the value of the key is a BsonBinary, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonBinary, returns false if the document does not contain the key. */ public boolean isBinary(final Object key) { if (!containsKey(key)) { return false; } return get(key).isBinary(); }
/** * Returns true if the value of the key is a BsonNull, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonNull, returns false if the document does not contain the key. */ public boolean isNull(final Object key) { if (!containsKey(key)) { return false; } return get(key).isNull(); }
/** * Returns true if the value of the key is a BsonBoolean, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonBoolean, returns false if the document does not contain the key. */ public boolean isBoolean(final Object key) { if (!containsKey(key)) { return false; } return get(key).isBoolean(); }
/** * Returns true if the value of the key is a BsonNumber, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonNumber, returns false if the document does not contain the key. */ public boolean isNumber(final Object key) { if (!containsKey(key)) { return false; } return get(key).isNumber(); }
/** * Returns true if the value of the key is a BsonInt32, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonInt32, returns false if the document does not contain the key. */ public boolean isInt32(final Object key) { if (!containsKey(key)) { return false; } return get(key).isInt32(); }
/** * Returns true if the value of the key is a BsonInt64, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonInt64, returns false if the document does not contain the key. */ public boolean isInt64(final Object key) { if (!containsKey(key)) { return false; } return get(key).isInt64(); }
private static Date getLastWriteDate(final BsonDocument isMasterResult) { if (!isMasterResult.containsKey("lastWrite")) { return null; } return new Date(isMasterResult.getDocument("lastWrite").getDateTime("lastWriteDate").getValue()); }
private void beforeFields(final BsonWriter bsonWriter, final EncoderContext encoderContext, final BsonDocument value) { if (encoderContext.isEncodingCollectibleDocument() && value.containsKey(ID_FIELD_NAME)) { bsonWriter.writeName(ID_FIELD_NAME); writeValue(bsonWriter, encoderContext, value.get(ID_FIELD_NAME)); } }
Authenticator getAuthenticatorFromIsMasterResult(final BsonDocument isMasterResult, final ConnectionDescription connectionDescription) { if (isMasterResult.containsKey("saslSupportedMechs")) { BsonArray saslSupportedMechs = isMasterResult.getArray("saslSupportedMechs"); AuthenticationMechanism mechanism = saslSupportedMechs.contains(DEFAULT_MECHANISM_NAME) ? SCRAM_SHA_256 : SCRAM_SHA_1; return new ScramShaAuthenticator(getMongoCredentialWithCache().withMechanism(mechanism)); } else { return getLegacyDefaultAuthenticator(connectionDescription); } }
private ConnectionDescription applyGetLastErrorResult(final BsonDocument getLastErrorResult, final ConnectionDescription connectionDescription) { ConnectionId connectionId; if (getLastErrorResult.containsKey("connectionId")) { connectionId = connectionDescription.getConnectionId().withServerValue(getLastErrorResult.getNumber("connectionId").intValue()); } else { connectionId = connectionDescription.getConnectionId(); } return connectionDescription.withConnectionId(connectionId); }
private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { if (!isInline(description) || result.containsKey(CURSOR)) { return cursorDocumentToQueryResult(result.getDocument(CURSOR), description.getServerAddress()); } else { return new QueryResult<T>(namespace, BsonDocumentWrapperHelper.<T>toList(result, RESULT), 0L, description.getServerAddress()); } }