/** * Gets the value in this document for the given field name. * * @param fieldName The name of the field * @return The field value, if found, or null otherwise */ default Value get(CharSequence fieldName) { return get(fieldName, null); }
/** * Gets the field in this document with the given field name. * * @param fieldName The name of the field * @return The field, if found, or null otherwise */ default Field getField(CharSequence fieldName) { Value value = get(fieldName); return value != null ? new BasicField(fieldName, value) : null; }
@Override public int compareToUsingSimilarFields(Document that) { if (that == null) return 1; int diff = 0; // We don't care about order, so just go through by this Document's fields ... for (Map.Entry<CharSequence, Value> entry : fields.entrySet()) { CharSequence key = entry.getKey(); diff = compareNonNull(this.get(key), that.get(key)); if (diff != 0) return diff; } return 0; }
/** * Get the boolean value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a boolean * @return The boolean field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * boolean */ default boolean getBoolean(CharSequence fieldName, boolean defaultValue) { Value value = get(fieldName); return value != null && value.isBoolean() ? value.asBoolean().booleanValue() : defaultValue; }
/** * Get the double value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a double * @return The double field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * double */ default double getDouble(CharSequence fieldName, double defaultValue) { Value value = get(fieldName); return value != null && value.isDouble() ? value.asDouble().doubleValue() : defaultValue; }
/** * Get the long value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a long value * @return The long field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a long * value */ default long getLong(CharSequence fieldName, long defaultValue) { Value value = get(fieldName); return value != null && value.isLong() ? value.asLong().longValue() : defaultValue; }
/** * Get the float value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a double * @return The double field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * double */ default float getFloat(CharSequence fieldName, float defaultValue) { Value value = get(fieldName); return value != null && value.isFloat() ? value.asFloat().floatValue() : defaultValue; }
/** * Get the integer value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a integer * @return The integer field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * integer */ default int getInteger(CharSequence fieldName, int defaultValue) { Value value = get(fieldName); return value != null && value.isInteger() ? value.asInteger().intValue() : defaultValue; }
/** * Get the big decimal value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a big decimal * @return The big decimal field value, if found, or null if there is no such field or if the value is not a big decimal */ default BigDecimal getBigDecimal(CharSequence fieldName, BigDecimal defaultValue) { Value value = get(fieldName); return value != null && value.isBigDecimal() ? value.asBigDecimal() : defaultValue; }
/** * Get the integer value in this document for the given field name. * * @param fieldName The name of the field * @return The integer field value, if found, or null if there is no such field or if the value is not an integer */ default Integer getInteger(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isInteger() ? value.asInteger() : null; }
/** * Get the integer value in this document for the given field name. * * @param fieldName The name of the field * @return The long field value, if found, or null if there is no such field or if the value is not a long value */ default Long getLong(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isLong() ? value.asLong() : null; }
/** * Get the double value in this document for the given field name. * * @param fieldName The name of the field * @return The double field value, if found, or null if there is no such field or if the value is not a double */ default Float getFloat(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isFloat() ? value.asFloat() : null; }
/** * Get the Base64 encoded binary value in this document for the given field name. * * @param fieldName The name of the field * @return The binary field value, if found, or null if there is no such field or if the value is not a binary value */ default byte[] getBytes(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isBinary() ? value.asBytes() : null; }
/** * Get the array value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default array that should be returned if there is no such field * @return The array field value (as a list), if found, or the default value if there is no such field or if the value is not * an array */ default Array getArray(CharSequence fieldName, Array defaultValue) { Value value = get(fieldName); return value != null && value.isArray() ? value.asArray() : defaultValue; }
/** * Get the double value in this document for the given field name. * * @param fieldName The name of the field * @return The double field value, if found, or null if there is no such field or if the value is not a double */ default Double getDouble(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isDouble() ? value.asDouble() : null; }
/** * Get the document value in this document for the given field name. * * @param fieldName The name of the field * @return The document field value, if found, or null if there is no such field or if the value is not a document */ default Document getDocument(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isDocument() ? value.asDocument() : null; }
/** * Get the boolean value in this document for the given field name. * * @param fieldName The name of the field * @return The boolean field value, if found, or null if there is no such field or if the value is not a boolean */ default Boolean getBoolean(CharSequence fieldName) { Value value = get(fieldName); return value != null && value.isBoolean() ? value.asBoolean() : null; }
/** * Get the big integer value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a big integer * @return The big integer field value, if found, or null if there is no such field or if the value is not a big integer */ default BigInteger getBigInteger(CharSequence fieldName, BigInteger defaultValue) { Value value = get(fieldName); return value != null && value.isBigInteger() ? value.asBigInteger() : defaultValue; }
/** * Get the number value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a number * @return The number field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * number */ default Number getNumber(CharSequence fieldName, Number defaultValue) { Value value = get(fieldName); return value != null && value.isNumber() ? value.asNumber() : defaultValue; }
/** * Get the string value in this document for the given field name. * * @param fieldName The name of the field * @param defaultValue the default value to return if there is no such field or if the value is not a string * @return The string field value if found, or <code>defaultValue</code> if there is no such field or if the value is not a * string */ default String getString(CharSequence fieldName, String defaultValue) { Value value = get(fieldName); return value != null && value.isString() ? value.asString() : defaultValue; }