Interface AMDistanceComparator<T>

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AMDistanceComparator<T>
Compares two values, returning a long value representing the distance between them. The meaning of this distance is dependent on the kind of value.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    compare(T value1, T value2)
    Compare the two values, returning a long value representing how far they are from each other.
    default Comparator<T>
    Return a comparator that is equivalent to this AMDistanceComparator.
  • Method Details

    • compare

      long compare(T value1, T value2)
      Compare the two values, returning a long value representing how far they are from each other. The meaning of this distance depends on the kind of attribute.
      Parameters:
      value1 - the first value
      value2 - the second value
      Returns:
      the distance between the two values
    • toComparator

      default Comparator<T> toComparator()
      Return a comparator that is equivalent to this AMDistanceComparator. Implementations of this interface must use saturated arithmetic, guaranteeing the following conditions:

       
       if amDistanceComparator.compare(a, b) < 0 then
       amDistanceComparator.toComparator().compare(a, b) < 0
      
       if amDistanceComparator.compare(a, b) > 0 then
       amDistanceComparator.toComparator().compare(a, b) > 0
      
       if amDistanceComparator.compare(a, b) = 0 then
       amDistanceComparator.toComparator().compare(a, b) = 0
       
       

      Returns:
      a Comparator equivalent to this AMDistanceComparator