Class SortByComparator<R>

java.lang.Object
org.apache.sis.internal.filter.SortByComparator<R>
Type Parameters:
R - the type of resources (typically Feature) to sort.
All Implemented Interfaces:
Serializable, Comparator<R>, SortBy<R>

public final class SortByComparator<R> extends Object implements SortBy<R>, Serializable
Comparator sorting features using an array of SortProperty elements applied in order.
Since:
1.0
Version:
1.1
See Also:
  • Field Details

  • Constructor Details

    • SortByComparator

      private SortByComparator(SortProperty<R> p)
      Creates a new comparator for the given sort expression. This is shortcut for the common case where there is a single expression.
      Parameters:
      p - the property to wrap in a SortBy comparator.
    • SortByComparator

      private SortByComparator(Map<?,SortProperty<R>> merged)
      Creates a new comparator with the values of given map. The map is used for removing duplicated expressions.
  • Method Details

    • create

      public static <R> SortByComparator<R> create(SortProperty<R>[] properties)
      Creates a new comparator for the given sort expressions.
      Type Parameters:
      R - the type of resources (typically Feature) to sort.
      Parameters:
      properties - the sort order.
      Returns:
      the comparator, or null if the given array is empty.
    • concatenate

      public static <R> SortBy<? super R> concatenate(SortBy<? super R> sort, Comparator<? super R> comparator)
      Creates a new comparator as the concatenation of the two given comparators. The first comparator is used first, and if two resources are equal then the second comparator is used.
      Type Parameters:
      R - the type of resources (typically Feature) to sort.
      Parameters:
      sort - the first "sort by" to use, or null if none.
      comparator - the second "sort by" to use.
      Returns:
      concatenation of the two comparators.
    • concatenate

      public static <R> SortBy<R> concatenate(SortBy<R> s1, SortBy<R> s2)
      Creates a new comparator as the concatenation of the two given comparators. The first comparator is used first, and if two resources are equal then the second comparator is used.
      Type Parameters:
      R - the type of resources (typically Feature) to sort.
      Parameters:
      s1 - the first "sort by" to use.
      s2 - the second "sort by" to use.
      Returns:
      concatenation of the two comparators.
    • addAll

      private static <R> void addAll(List<SortProperty<R>> properties, Map<ValueReference<? super R,?>,SortProperty<R>> merged)
      Adds all elements of the properties list into the merged map. If two SortProperty instances use the same ValueReference, then only the first occurrence is retained.
    • getSortProperties

      public List<SortProperty<R>> getSortProperties()
      Returns the properties whose values are used for sorting. The list shall have a minimum of one element.
      Specified by:
      getSortProperties in interface SortBy<R>
    • compare

      public int compare(R r1, R r2)
      Compares two resources for order. Returns a negative number if r1 should be sorted before r2, a positive number if r2 should be after r1, or 0 if both resources are equal. The ordering of null resources or null property values is unspecified.
      Specified by:
      compare in interface Comparator<R>
    • thenComparing

      public Comparator<R> thenComparing(Comparator<? super R> other)
      Returns a comparator as the concatenation of this comparator with the given one. This comparator is used first, and if two resources are equal then the other comparator is used.
      Specified by:
      thenComparing in interface Comparator<R>
      Parameters:
      other - the other comparator to be used when this comparator considers two resources as equal.
      Returns:
      concatenation of this comparator with the given one.