Interface SerializableComparator<T>

All Superinterfaces:
Comparator<T>, Serializable
All Known Implementing Classes:
SerializableComparatorWrapperClass
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 SerializableComparator<T> extends Comparator<T>, Serializable
Serializable version of Comparator.
  • Method Details

    • reversed

      default SerializableComparator<T> reversed()
      Returns a comparator that imposes the reverse ordering of this comparator.
      Specified by:
      reversed in interface Comparator<T>
      Returns:
      a comparator that imposes the reverse ordering of this comparator.
      Since:
      1.8
    • thenComparing

      default SerializableComparator<T> thenComparing(SerializableComparator<? super T> other)
      Returns a lexicographic-order comparator with another comparator. If this SerializableComparator considers two elements equal, i.e. compare(a, b) == 0, other is used to determine the order.
      Parameters:
      other - the other comparator to be used when this comparator compares two objects that are equal.
      Returns:
      a lexicographic-order comparator composed of this and then the other comparator
      Throws:
      NullPointerException - if the argument is null.
      Since:
      1.8
    • thenComparing

      default <U> SerializableComparator<T> thenComparing(SerializableFunction<? super T,? extends U> keyExtractor, SerializableComparator<? super U> keyComparator)
      Returns a lexicographic-order comparator with a function that extracts a key to be compared with the given SerializableComparator.
      Type Parameters:
      U - the type of the sort key
      Parameters:
      keyExtractor - the function used to extract the sort key
      keyComparator - the SerializableComparator used to compare the sort key
      Returns:
      a lexicographic-order comparator composed of this comparator and then comparing on the key extracted by the keyExtractor function
      Throws:
      NullPointerException - if either argument is null.
      Since:
      1.8
      See Also:
    • thenComparing

      default <U extends Comparable<? super U>> SerializableComparator<T> thenComparing(SerializableFunction<? super T,? extends U> keyExtractor)
      Returns a lexicographic-order comparator with a function that extracts a Comparable sort key.
      Type Parameters:
      U - the type of the Comparable sort key
      Parameters:
      keyExtractor - the function used to extract the Comparable sort key
      Returns:
      a lexicographic-order comparator composed of this and then the Comparable sort key.
      Throws:
      NullPointerException - if the argument is null.
      Since:
      1.8
      See Also:
    • thenComparingInt

      default SerializableComparator<T> thenComparingInt(SerializableToIntFunction<? super T> keyExtractor)
      Returns a lexicographic-order comparator with a function that extracts an int sort key.
      Parameters:
      keyExtractor - the function used to extract the integer sort key
      Returns:
      a lexicographic-order comparator composed of this and then the int sort key
      Throws:
      NullPointerException - if the argument is null.
      Since:
      1.8
      See Also:
    • thenComparingLong

      default SerializableComparator<T> thenComparingLong(SerializableToLongFunction<? super T> keyExtractor)
      Returns a lexicographic-order comparator with a function that extracts a long sort key.
      Parameters:
      keyExtractor - the function used to extract the long sort key
      Returns:
      a lexicographic-order comparator composed of this and then the long sort key
      Throws:
      NullPointerException - if the argument is null.
      Since:
      1.8
      See Also:
    • thenComparingDouble

      default SerializableComparator<T> thenComparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
      Returns a lexicographic-order comparator with a function that extracts a double sort key.
      Parameters:
      keyExtractor - the function used to extract the double sort key
      Returns:
      a lexicographic-order comparator composed of this and then the double sort key
      Throws:
      NullPointerException - if the argument is null.
      Since:
      1.8
      See Also:
    • reverseOrder

      static <T extends Comparable<? super T>> SerializableComparator<T> reverseOrder()
      Returns a comparator that imposes the reverse of the natural ordering.

      The returned comparator throws NullPointerException when comparing null.

      Type Parameters:
      T - the Comparable type of element to be compared
      Returns:
      a comparator that imposes the reverse of the natural ordering on Comparable objects.
      Since:
      1.8
      See Also:
    • naturalOrder

      static <T extends Comparable<? super T>> SerializableComparator<T> naturalOrder()
      Returns a comparator that compares Comparable objects in natural order.

      The returned comparator throws NullPointerException when comparing null.

      Type Parameters:
      T - the Comparable type of element to be compared
      Returns:
      a comparator that imposes the natural ordering on Comparable objects.
      Since:
      1.8
      See Also:
    • nullsFirst

      static <T> SerializableComparator<T> nullsFirst(SerializableComparator<? super T> comparator)
      Returns a null-friendly comparator that considers null to be less than non-null. When both are null, they are considered equal. If both are non-null, the specified Comparator is used to determine the order. If the specified comparator is null, then the returned comparator considers all non-null values to be equal.
      Type Parameters:
      T - the type of the elements to be compared
      Parameters:
      comparator - a SerializableComparator for comparing non-null values
      Returns:
      a comparator that considers null to be less than non-null, and compares non-null objects with the supplied SerializableComparator.
      Since:
      1.8
    • nullsLast

      static <T> SerializableComparator<T> nullsLast(SerializableComparator<? super T> comparator)
      Returns a null-friendly comparator that considers null to be greater than non-null. When both are null, they are considered equal. If both are non-null, the specified Comparator is used to determine the order. If the specified comparator is null, then the returned comparator considers all non-null values to be equal.
      Type Parameters:
      T - the type of the elements to be compared
      Parameters:
      comparator - a SerializableComparator for comparing non-null values
      Returns:
      a comparator that considers null to be greater than non-null, and compares non-null objects with the supplied SerializableComparator.
      Since:
      1.8
    • comparing

      static <T, U> SerializableComparator<T> comparing(SerializableFunction<? super T,? extends U> keyExtractor, SerializableComparator<? super U> keyComparator)
      Accepts a function that extracts a sort key from a type T, and returns a SerializableComparator<T> that compares by that sort key using the specified SerializableComparator.

      The returned comparator is serializable.

      Type Parameters:
      T - the type of element to be compared
      U - the type of the sort key
      Parameters:
      keyExtractor - the function used to extract the sort key
      keyComparator - the SerializableComparator used to compare the sort key
      Returns:
      a comparator that compares by an extracted key using the specified SerializableComparator
      Throws:
      NullPointerException - if either argument is null
      Since:
      1.8
    • comparing

      static <T, U extends Comparable<? super U>> SerializableComparator<T> comparing(SerializableFunction<? super T,? extends U> keyExtractor)
      Accepts a function that extracts a Comparable sort key from a type T, and returns a Comparator<T> that compares by that sort key.
      Type Parameters:
      T - the type of element to be compared
      U - the type of the Comparable sort key
      Parameters:
      keyExtractor - the function used to extract the Comparable sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if the argument is null
      Since:
      1.8
    • comparingInt

      static <T> SerializableComparator<T> comparingInt(SerializableToIntFunction<? super T> keyExtractor)
      Accepts a function that extracts an int sort key from a type T, and returns a Comparator<T> that compares by that sort key.
      Type Parameters:
      T - the type of element to be compared
      Parameters:
      keyExtractor - the function used to extract the integer sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if the argument is null
      Since:
      1.8
      See Also:
    • comparingLong

      static <T> SerializableComparator<T> comparingLong(SerializableToLongFunction<? super T> keyExtractor)
      Accepts a function that extracts a long sort key from a type T, and returns a Comparator<T> that compares by that sort key.
      Type Parameters:
      T - the type of element to be compared
      Parameters:
      keyExtractor - the function used to extract the long sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if the argument is null
      Since:
      1.8
      See Also:
    • comparingDouble

      static <T> SerializableComparator<T> comparingDouble(SerializableToDoubleFunction<? super T> keyExtractor)
      Accepts a function that extracts a double sort key from a type T, and returns a SerializableComparator<T> that compares by that sort key.
      Type Parameters:
      T - the type of element to be compared
      Parameters:
      keyExtractor - the function used to extract the double sort key
      Returns:
      a comparator that compares by an extracted key
      Throws:
      NullPointerException - if the argument is null
      Since:
      1.8
      See Also: