Interface IntComparator

All Superinterfaces:
Comparator<Integer>
All Known Implementing Classes:
AbstractIntComparator
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 IntComparator extends Comparator<Integer>
A type-specific Comparator; provides methods to compare two primitive types both as objects and as primitive types.

Note that fastutil provides a corresponding abstract class that can be used to implement this interface just by specifying the type-specific comparator.

See Also:
  • Method Details

    • compare

      int compare(int k1, int k2)
      Compares its two primitive-type arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
      Returns:
      a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
      See Also:
    • reversed

      default IntComparator reversed()
      Specified by:
      reversed in interface Comparator<Integer>
    • compare

      @Deprecated default int compare(Integer ok1, Integer ok2)
      Deprecated.
      Please use the corresponding type-specific method instead.
      Specified by:
      compare in interface Comparator<Integer>
      Implementation Specification:
      This implementation delegates to the corresponding type-specific method.
    • thenComparing

      default IntComparator thenComparing(IntComparator second)
      Return a new comparator that first uses this comparator, then uses the second comparator if this comparator compared the two elements as equal.
      See Also:
    • thenComparing

      default Comparator<Integer> thenComparing(Comparator<? super Integer> second)
      Specified by:
      thenComparing in interface Comparator<Integer>
    • comparing

      static <U extends Comparable<? super U>> IntComparator comparing(Int2ObjectFunction<? extends U> keyExtractor)
      Accepts a function that extracts a Comparable sort key from a primitive key, and returns a comparator that compares by that sort key.

      The returned comparator is serializable if the specified function is also serializable.

      Parameters:
      keyExtractor - the function used to extract the Comparable sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if keyExtractor is null
    • comparing

      static <U extends Comparable<? super U>> IntComparator comparing(Int2ObjectFunction<? extends U> keyExtractor, Comparator<? super U> keyComparator)
      Accepts a function that extracts a sort key from a primitive key, and returns a comparator that compares by that sort key using the specified Comparator.

      The returned comparator is serializable if the specified function and comparator are both serializable.

      Parameters:
      keyExtractor - the function used to extract the sort key
      keyComparator - the Comparator used to compare the sort key
      Returns:
      a comparator that compares by an extracted key using the specified Comparator
      Throws:
      NullPointerException - if keyExtractor or keyComparator are null
    • comparingInt

      static IntComparator comparingInt(Int2IntFunction keyExtractor)
      Accepts a function that extracts an int sort key from a primitive key, and returns a comparator that compares by that sort key.

      The returned comparator is serializable if the specified function is also serializable.

      Parameters:
      keyExtractor - the function used to extract the integer sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if keyExtractor is null
    • comparingLong

      static IntComparator comparingLong(Int2LongFunction keyExtractor)
      Accepts a function that extracts an long sort key from a primitive key, and returns a comparator that compares by that sort key.

      The returned comparator is serializable if the specified function is also serializable.

      Parameters:
      keyExtractor - the function used to extract the long sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if keyExtractor is null
    • comparingDouble

      static IntComparator comparingDouble(Int2DoubleFunction keyExtractor)
      Accepts a function that extracts an double sort key from a primitive key, and returns a comparator that compares by that sort key.

      The returned comparator is serializable if the specified function is also serializable.

      Parameters:
      keyExtractor - the function used to extract the double sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if keyExtractor is null