Class ReverseComparator<T>

  • All Implemented Interfaces:
    java.util.Comparator<T>

    public class ReverseComparator<T>
    extends java.lang.Object
    implements java.util.Comparator<T>
    This class is comparator which reverse the ordering of a given comparator.
    Version:
    $Revision: 21407 $
    Author:
    Olivier Dedieu
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Comparator<T> comparator  
      static java.lang.String REVISION  
    • Constructor Summary

      Constructors 
      Constructor Description
      ReverseComparator()
      Defaut constructor reverse NaturalComparator Objects mus be Comparable
      ReverseComparator​(java.util.Comparator<T> comparator)
      This constructor will reverse returned value by given comparator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(T o1, T o2)  
      java.util.Comparator<T> getReversedComparator()
      Retrieve the Comparator this ReverseComparator is reversing or null when the natural Comparator is reversed.
      • Methods inherited from class java.lang.Object

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

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • comparator

        protected java.util.Comparator<T> comparator
    • Constructor Detail

      • ReverseComparator

        public ReverseComparator()
        Defaut constructor reverse NaturalComparator Objects mus be Comparable
      • ReverseComparator

        public ReverseComparator​(java.util.Comparator<T> comparator)
        This constructor will reverse returned value by given comparator.
        Parameters:
        comparator - used to compare object
    • Method Detail

      • getReversedComparator

        public java.util.Comparator<T> getReversedComparator()
        Retrieve the Comparator this ReverseComparator is reversing or null when the natural Comparator is reversed.
        Returns:
        the Comparator instance being used or null if we are reversing the natural Comparator of the objects.
      • compare

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