@Override public int compareTo(Value that) { return value.compareTo(that); }
/** * Compare two {@link Value} objects, which may or may not be null. * * @param value1 the first value object, may be null * @param value2 the second value object, which may be null * @return a negative integer if the first value is less than the second, zero if the values are equivalent (including if both * are null), or a positive integer if the first value is greater than the second */ static int compareTo(Value value1, Value value2) { if (value1 == null) return isNull(value2) ? 0 : -1; return value1.compareTo(value2); }
@Override default int compareTo(Field that) { if (that == null) return 1; int diff = this.getName().toString().compareTo(that.getName().toString()); if (diff != 0) return diff; return this.getValue().compareTo(that.getValue()); } }
/** * Semantically compare two values. This includes comparing numeric values of different types (e.g., an integer and long), * and {@code null} and {@link Value#nullValue()} references. * * @param value1 the first value; may be null * @param value2 the second value; may be null * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ protected int compare(Value value1, Value value2) { if (value1 == null) return Value.isNull(value2) ? 0 : 1; return value1.comparable().compareTo(value2.comparable()); }
@Override default int compareTo(Entry that) { if (that == null) return 1; int diff = this.getIndex() - that.getIndex(); if (diff != 0) return diff; return this.getValue().compareTo(that.getValue()); } }
/** * Semantically compare two non-null values. This includes comparing numeric values of different types * (e.g., an integer and long), but excludes {@code null} and {@link Value#nullValue()} references. * * @param value1 the first value; may be null * @param value2 the second value; may be null * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ protected int compareNonNull(Value value1, Value value2) { if (Value.isNull(value1) || Value.isNull(value2)) return 0; return value1.comparable().compareTo(value2.comparable()); }
@Override public boolean hasAll(Document that) { if (that == null) return true; if (this.size() < that.size()) { // Can't have all of 'that' if 'that' is bigger ... return false; } return that.stream().allMatch(field -> { Value thatValue = field.getValue(); Value thisValue = this.get(field.getName()); return Value.compareTo(thisValue, thatValue) == 0; }); }
@Override public int compareTo(Document.Field that) { if ( this == that ) return 0; int diff = Strings.compareTo(this.getName(),that.getName()); if ( diff != 0 ) return diff; return Value.compareTo(this.getValue(),that.getValue()); } }
@Override public int compareTo(Array that) { if (that == null) return 1; int size = this.size(); if (size != that.size()) return size - that.size(); Array thatArray = that; for (int i = 0; i != size; ++i) { Value thatValue = thatArray.get(i); Value thisValue = get(i); int diff = thatValue.compareTo(thisValue); if (diff != 0) return diff; } return 0; }
@Override public int compareTo(Array.Entry that) { if ( this == that ) return 0; if ( this.getIndex() != that.getIndex() ) return this.getIndex() - that.getIndex(); return Value.compareTo(this.getValue(),that.getValue()); } }
@Override public int compareTo(Value that) { return value.compareTo(that); }
/** * Compare two {@link Value} objects, which may or may not be null. * * @param value1 the first value object, may be null * @param value2 the second value object, which may be null * @return a negative integer if the first value is less than the second, zero if the values are equivalent (including if both * are null), or a positive integer if the first value is greater than the second */ static int compareTo(Value value1, Value value2) { if (value1 == null) return isNull(value2) ? 0 : -1; return value1.compareTo(value2); }
@Override default int compareTo(Field that) { if (that == null) return 1; int diff = this.getName().toString().compareTo(that.getName().toString()); if (diff != 0) return diff; return this.getValue().compareTo(that.getValue()); } }
/** * Semantically compare two values. This includes comparing numeric values of different types (e.g., an integer and long), * and {@code null} and {@link Value#nullValue()} references. * * @param value1 the first value; may be null * @param value2 the second value; may be null * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ protected int compare(Value value1, Value value2) { if (value1 == null) return Value.isNull(value2) ? 0 : 1; return value1.comparable().compareTo(value2.comparable()); }
@Override default int compareTo(Entry that) { if (that == null) return 1; int diff = this.getIndex() - that.getIndex(); if (diff != 0) return diff; return this.getValue().compareTo(that.getValue()); } }
/** * Semantically compare two non-null values. This includes comparing numeric values of different types * (e.g., an integer and long), but excludes {@code null} and {@link Value#nullValue()} references. * * @param value1 the first value; may be null * @param value2 the second value; may be null * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ protected int compareNonNull(Value value1, Value value2) { if (Value.isNull(value1) || Value.isNull(value2)) return 0; return value1.comparable().compareTo(value2.comparable()); }
@Override public boolean hasAll(Document that) { if (that == null) return true; if (this.size() < that.size()) { // Can't have all of 'that' if 'that' is bigger ... return false; } return that.stream().allMatch(field -> { Value thatValue = field.getValue(); Value thisValue = this.get(field.getName()); return Value.compareTo(thisValue, thatValue) == 0; }); }
@Override public int compareTo(Document.Field that) { if ( this == that ) return 0; int diff = Strings.compareTo(this.getName(),that.getName()); if ( diff != 0 ) return diff; return Value.compareTo(this.getValue(),that.getValue()); } }
@Override public int compareTo(Array that) { if (that == null) return 1; int size = this.size(); if (size != that.size()) return size - that.size(); Array thatArray = that; for (int i = 0; i != size; ++i) { Value thatValue = thatArray.get(i); Value thisValue = get(i); int diff = thatValue.compareTo(thisValue); if (diff != 0) return diff; } return 0; }
@Override public int compareTo(Array.Entry that) { if ( this == that ) return 0; if ( this.getIndex() != that.getIndex() ) return this.getIndex() - that.getIndex(); return Value.compareTo(this.getValue(),that.getValue()); } }