## org.springframework.util.comparator
Class InvertibleComparator

    java.lang.Object
      org.springframework.util.comparator.InvertibleComparator

All Implemented Interfaces:
  Serializable, Comparator

    public class InvertibleComparator

extends Object
implements Comparator, Serializable

A decorator for a comparator, with an "ascending" flag denoting whether comparison results should be treated in forward (standard ascending) order or flipped for reverse (descending) order.

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

Constructor Summary
`InvertibleComparator(Comparator comparator)` Create an InvertibleComparator that sorts ascending by default.
`InvertibleComparator(Comparator comparator, boolean ascending)` Create an InvertibleComparator that sorts based on the provided order.

Method Summary
`int` `compare(Object o1, Object o2)`
`boolean` `equals(Object obj)`
`int` `hashCode()`
`void` `invertOrder()` Invert the sort order: ascending -> descending or descending -> ascending.
`boolean` `isAscending()` Return the sort order: ascending (true) or descending (false).
`void` `setAscending(boolean ascending)` Specify the sort order: ascending (true) or descending (false).
`String` `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### InvertibleComparator

    public InvertibleComparator(Comparator comparator)

  Create an InvertibleComparator that sorts ascending by default. For the actual comparison, the specified Comparator will be used.

  Parameters:
    `comparator` - the comparator to decorate

### InvertibleComparator

    public InvertibleComparator(Comparator comparator,
                                boolean ascending)

  Create an InvertibleComparator that sorts based on the provided order. For the actual comparison, the specified Comparator will be used.

  Parameters:
    `comparator` - the comparator to decorate
    `ascending` - the sort order: ascending (true) or descending (false)

Method Detail

### setAscending

    public void setAscending(boolean ascending)

  Specify the sort order: ascending (true) or descending (false).

### isAscending

    public boolean isAscending()

  Return the sort order: ascending (true) or descending (false).

### invertOrder

    public void invertOrder()

  Invert the sort order: ascending -> descending or descending -> ascending.

### compare

    public int compare(Object o1,
                       Object o2)

  Specified by:
    `compare` in interface `Comparator`

### equals

    public boolean equals(Object obj)

  Specified by:
    `equals` in interface `Comparator`
  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

Copyright © 2002-2008 The Spring Framework.