net.sf.jagg
Class PropertiesComparator<T>

java.lang.Object
  extended by net.sf.jagg.PropertiesComparator<T>
All Implemented Interfaces:
java.util.Comparator<T>

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

This class represents a flexible Comparator that is capable of comparing two objects based on a dynamic list of properties of the objects of type T. This class is used internally by Aggregation to sort a List<T> according to a specified list of properties.

Since:
0.1.0
Author:
Randy Gettman

Constructor Summary
PropertiesComparator(java.util.List<java.lang.String> properties)
          Construct a PropertiesComparator that pays attention to the given List of properties in the generic type T.
 
Method Summary
 int compare(T o1, T o2)
          Compares the given objects to determine order.
 boolean equals(java.lang.Object obj)
          Indicates whether the given PropertiesComparator is equal to this PropertiesComparator.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesComparator

public PropertiesComparator(java.util.List<java.lang.String> properties)
Construct a PropertiesComparator that pays attention to the given List of properties in the generic type T. All properties must be Comparable.

Parameters:
properties - A List<String> of properties.
Method Detail

compare

public int compare(T o1,
                   T o2)
            throws java.lang.UnsupportedOperationException

Compares the given objects to determine order. Fulfills the Comparator contract by returning a negative integer, 0, or a positive integer if o1 is less than, equal to, or greater than o2.

Nulls properties compare equal to each other, and a null property compares greater than a non-null property.

Specified by:
compare in interface java.util.Comparator<T>
Parameters:
o1 - The left-hand-side object to compare.
o2 - The right-hand-side object to compare.
Returns:
A negative integer, 0, or a positive integer if o1 is less than, equal to, or greater than o2.
Throws:
java.lang.UnsupportedOperationException - If any property specified in the constructor doesn't correspond to a no-argument "get<Property>" getter method in T, or if the property's type is not Comparable.

equals

public boolean equals(java.lang.Object obj)
Indicates whether the given PropertiesComparator is equal to this PropertiesComparator. All property names must match in order.

Specified by:
equals in interface java.util.Comparator<T>
Overrides:
equals in class java.lang.Object
Parameters:
obj - The other PropertiesComparator.


Copyright © 2010-2013 jAgg Team. All Rights Reserved.