de.tkuhn.util
Class OrderComparator<T>

java.lang.Object
  extended by de.tkuhn.util.OrderComparator<T>
All Implemented Interfaces:
java.util.Comparator<T>

public class OrderComparator<T>
extends java.lang.Object
implements java.util.Comparator<T>

This class defines a Comparator that is a wrapper for other Comparators an can change the order of their comparisons.

Version:
0.9.3
Author:
Tilmann Kuhn
See Also:
Comparator

Field Summary
static boolean ASCENDING
          Ascending compare order
static boolean DESCENDING
          Descending compare order
 
Constructor Summary
OrderComparator()
          Creates a new instance of OrderComparator using ascending order
OrderComparator(boolean order)
          Creates a new instance of OrderComparator using the given order.
OrderComparator(java.util.Comparator<T> comparator)
          Creates a new instance of OrderComparator using ascending order, delegating to the given Comparator.
OrderComparator(java.util.Comparator<T> comparator, boolean order)
          Creates a new instance of OrderComparator using the given order, delegating to the given Comparator.
 
Method Summary
 int compare(T o1, T o2)
          Implementation of compare(obj,obj) in the interface java.util.Comparator.
 java.util.Comparator<T> getComparator()
          Get the Comparator that is wrapped by this OrderComparator.
 boolean getOrder()
          Get the order this wrapper uses to transform the comparisons to.
 void setComparator(java.util.Comparator<T> comparator)
          Set the Comparator that will be wrapped by this OrderComparator.
 void setOrder(boolean order)
          Set the order this wrapper will use to transform the comparisons to.
 
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
 

Field Detail

ASCENDING

public static final boolean ASCENDING
Ascending compare order

See Also:
Constant Field Values

DESCENDING

public static final boolean DESCENDING
Descending compare order

See Also:
Constant Field Values
Constructor Detail

OrderComparator

public OrderComparator()
Creates a new instance of OrderComparator using ascending order


OrderComparator

public OrderComparator(boolean order)
Creates a new instance of OrderComparator using the given order.

Parameters:
order - transform comparisons to this order

OrderComparator

public OrderComparator(java.util.Comparator<T> comparator)
Creates a new instance of OrderComparator using ascending order, delegating to the given Comparator.

Parameters:
comparator - Comparator to delegate comparisons to

OrderComparator

public OrderComparator(java.util.Comparator<T> comparator,
                       boolean order)
Creates a new instance of OrderComparator using the given order, delegating to the given Comparator.

Parameters:
comparator - Comparator to delegate comparisons to
order - transform comparisons to this order
Method Detail

getComparator

public java.util.Comparator<T> getComparator()
Get the Comparator that is wrapped by this OrderComparator.

Returns:
Value of property comparator.

setComparator

public void setComparator(java.util.Comparator<T> comparator)
Set the Comparator that will be wrapped by this OrderComparator.

Parameters:
comparator - New value of property comparator.

compare

public int compare(T o1,
                   T o2)
            throws java.lang.IllegalStateException
Implementation of compare(obj,obj) in the interface java.util.Comparator.

Specified by:
compare in interface java.util.Comparator<T>
Parameters:
o1 - row one to be compared
o2 - row two to be compared
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
Throws:
java.lang.IllegalStateException - if no comparator for delegation is set.

getOrder

public boolean getOrder()
Get the order this wrapper uses to transform the comparisons to.

Returns:
Value of property order.

setOrder

public void setOrder(boolean order)
Set the order this wrapper will use to transform the comparisons to.

Parameters:
order - New value of property order.


Copyright © Tilmann Kuhn