public int compare(@Nonnull Value left, @Nonnull Value right) {
    // First compare the types.
    TypeOrder leftType = TypeOrder.fromValue(left);
    TypeOrder rightType = TypeOrder.fromValue(right);
    int typeComparison = leftType.compareTo(rightType);
    if (typeComparison != 0) {
      return typeComparison;
    }

    // So they are the same type.
    switch (leftType) {
      case NULL:
        return 0; // Nulls are all equal.
      case BOOLEAN:
        return Boolean.compare(left.getBooleanValue(), right.getBooleanValue());
      case NUMBER:
        return compareNumbers(left, right);
      case TIMESTAMP:
        return compareTimestamps(left, right);
      case STRING:
        return compareStrings(left, right);
      case BLOB:
        return compareBlobs(left, right);
      case REF:
        return compareResourcePaths(left, right);
      case GEO_POINT:
        return compareGeoPoints(left, right);
      case ARRAY:
        return compareArrays(left, right);
      case OBJECT:
        return compareObjects(left, right);
      default:
        throw new IllegalArgumentException("Cannot compare " + leftType);
    }
  }
public int compare ( @ Nonnull Value left , @ Nonnull Value right ) { TypeOrder leftType = TypeOrder . fromValue ( left ) ; TypeOrder rightType = TypeOrder . fromValue ( right ) ; int typeComparison = leftType . compareTo ( rightType ) ; if ( typeComparison != 0 ) { return typeComparison ; } switch ( leftType ) { case NULL : return 0 ; case BOOLEAN : return Boolean . compare ( left . getBooleanValue ( ) , right . getBooleanValue ( ) ) ; case NUMBER : return compareNumbers ( left , right ) ; case TIMESTAMP : return compareTimestamps ( left , right ) ; case STRING : return compareStrings ( left , right ) ; case BLOB : return compareBlobs ( left , right ) ; case REF : return compareResourcePaths ( left , right ) ; case GEO_POINT : return compareGeoPoints ( left , right ) ; case ARRAY : return compareArrays ( left , right ) ; case OBJECT : return compareObjects ( left , right ) ; default : throw new IllegalArgumentException ( "Cannot compare " + leftType ) ; } }
Main comparison function for all Firestore types.

@return -1 is left < right, 0 if left == right, otherwise 1