|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.util.bean.BeanComparator
public class BeanComparator
A comparator which compares objects based on one or more bean properties. Nested properties
are fully supported. If a property is non-String and implements Comparable
then the
compareTo()
method is delegated to. Otherwise the property is converted to a String
and a Locale
aware Collator
is used to to compare property values.
Constructor Summary | |
---|---|
BeanComparator(Locale locale,
String... properties)
Constructs a BeanComparator for comparing beans based on the supplied set of properties, using the supplied Locale to collate Strings. |
|
BeanComparator(String... properties)
Constructs a BeanComparator for comparing beans based on the supplied set of properties, using the default system Locale to collate Strings. |
Method Summary | |
---|---|
int |
compare(Object o1,
Object o2)
Compares two JavaBeans for order. |
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 |
Constructor Detail |
---|
public BeanComparator(String... properties)
properties
- one or more property names to be used, in order, to sort beanspublic BeanComparator(Locale locale, String... properties)
locale
- the Locale to be used for collating Stringsproperties
- one or more property names to be used, in order, to sort beansMethod Detail |
---|
public int compare(Object o1, Object o2)
Compares two JavaBeans for order. Returns a negative integer, zero, or a positive integer as the first argument sorts earlier, equal to, or later than the second.
Iterates through the properties supplied in the constructor comparing the values of each property for the two beans. As soon as a property is found that supplied a non-equal ordering, the ordering is returned. If all properties are equal, will return 0.
compare
in interface Comparator<Object>
o1
- the first object to be compared, must not be null.o2
- the second object to be compared, must not be null.
ClassCastException
- if the arguments' types, or the types of the properties,
prevent them from being compared by this Comparator.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |