org.springframework.util.comparator

Class CompoundComparator<T>

  • java.lang.Object
    • org.springframework.util.comparator.CompoundComparator<T>
  • Type Parameters:
    T - the type of objects that may be compared by this comparator
    All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<T>

    Deprecated. 
    as of Spring Framework 5.0, in favor of the standard JDK 8 Comparator.thenComparing(Comparator)

    @Deprecated
    public class CompoundComparator<T>
    extends java.lang.Object
    implements java.util.Comparator<T>, java.io.Serializable
    A comparator that chains a sequence of one or more Comparators.

    A compound comparator calls each Comparator in sequence until a single Comparator returns a non-zero result, or the comparators are exhausted and zero is returned.

    This facilitates in-memory sorting similar to multi-column sorting in SQL. The order of any single Comparator in the list can also be reversed.

    Since:
    1.2.2
    Author:
    Keith Donald, Juergen Hoeller
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      CompoundComparator()
      Deprecated. 
      Construct a CompoundComparator with initially no Comparators.
      CompoundComparator(java.util.Comparator... comparators)
      Deprecated. 
      Construct a CompoundComparator from the Comparators in the provided array.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      void addComparator(java.util.Comparator<? extends T> comparator)
      Deprecated. 
      Add a Comparator to the end of the chain.
      void addComparator(java.util.Comparator<? extends T> comparator, boolean ascending)
      Deprecated. 
      Add a Comparator to the end of the chain using the provided sort order.
      int compare(T o1, T o2)
      Deprecated. 
       
      boolean equals(java.lang.Object other)
      Deprecated. 
       
      int getComparatorCount()
      Deprecated. 
      Returns the number of aggregated comparators.
      int hashCode()
      Deprecated. 
       
      void invertOrder()
      Deprecated. 
      Invert the sort order of each sort definition contained by this compound comparator.
      void invertOrder(int index)
      Deprecated. 
      Invert the sort order of the sort definition at the specified index.
      void setAscendingOrder(int index)
      Deprecated. 
      Change the sort order at the given index to ascending.
      void setComparator(int index, java.util.Comparator<? extends T> comparator)
      Deprecated. 
      Replace the Comparator at the given index.
      void setComparator(int index, java.util.Comparator<T> comparator, boolean ascending)
      Deprecated. 
      Replace the Comparator at the given index using the given sort order.
      void setDescendingOrder(int index)
      Deprecated. 
      Change the sort order at the given index to descending sort.
      java.lang.String toString()
      Deprecated. 
       
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • CompoundComparator

        public CompoundComparator()
        Deprecated. 
        Construct a CompoundComparator with initially no Comparators. Clients must add at least one Comparator before calling the compare method or an IllegalStateException is thrown.
      • CompoundComparator

        public CompoundComparator(java.util.Comparator... comparators)
        Deprecated. 
        Construct a CompoundComparator from the Comparators in the provided array.

        All Comparators will default to ascending sort order, unless they are InvertibleComparators.

        Parameters:
        comparators - the comparators to build into a compound comparator
        See Also:
        InvertibleComparator
    • Method Detail

      • addComparator

        public void addComparator(java.util.Comparator<? extends T> comparator)
        Deprecated. 
        Add a Comparator to the end of the chain.

        The Comparator will default to ascending sort order, unless it is a InvertibleComparator.

        Parameters:
        comparator - the Comparator to add to the end of the chain
        See Also:
        InvertibleComparator
      • addComparator

        public void addComparator(java.util.Comparator<? extends T> comparator,
                                  boolean ascending)
        Deprecated. 
        Add a Comparator to the end of the chain using the provided sort order.
        Parameters:
        comparator - the Comparator to add to the end of the chain
        ascending - the sort order: ascending (true) or descending (false)
      • setComparator

        public void setComparator(int index,
                                  java.util.Comparator<? extends T> comparator)
        Deprecated. 
        Replace the Comparator at the given index.

        The Comparator will default to ascending sort order, unless it is a InvertibleComparator.

        Parameters:
        index - the index of the Comparator to replace
        comparator - the Comparator to place at the given index
        See Also:
        InvertibleComparator
      • setComparator

        public void setComparator(int index,
                                  java.util.Comparator<T> comparator,
                                  boolean ascending)
        Deprecated. 
        Replace the Comparator at the given index using the given sort order.
        Parameters:
        index - the index of the Comparator to replace
        comparator - the Comparator to place at the given index
        ascending - the sort order: ascending (true) or descending (false)
      • invertOrder

        public void invertOrder()
        Deprecated. 
        Invert the sort order of each sort definition contained by this compound comparator.
      • invertOrder

        public void invertOrder(int index)
        Deprecated. 
        Invert the sort order of the sort definition at the specified index.
        Parameters:
        index - the index of the comparator to invert
      • setAscendingOrder

        public void setAscendingOrder(int index)
        Deprecated. 
        Change the sort order at the given index to ascending.
        Parameters:
        index - the index of the comparator to change
      • setDescendingOrder

        public void setDescendingOrder(int index)
        Deprecated. 
        Change the sort order at the given index to descending sort.
        Parameters:
        index - the index of the comparator to change
      • getComparatorCount

        public int getComparatorCount()
        Deprecated. 
        Returns the number of aggregated comparators.
      • compare

        public int compare(T o1,
                           T o2)
        Deprecated. 
        Specified by:
        compare in interface java.util.Comparator<T>
      • equals

        public boolean equals(java.lang.Object other)
        Deprecated. 
        Specified by:
        equals in interface java.util.Comparator<T>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Deprecated. 
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Deprecated. 
        Overrides:
        toString in class java.lang.Object