|
Copyright 2002 by aragost | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.aragost.util.BeanComparator
A class to compare beans on a list of specified properties. The compare is done one property at a time until a difference is found, or all properties are equal. It is useful for sorting a collection of beans, in particular if you not always want to sort on the same properties. There is support for implementing sorting similiar to e.g. Windows Explorer where the user can click on a column header to set the sorting.
Constructor Summary | |
BeanComparator()
Create a new BeanComparator |
|
BeanComparator(java.lang.String configurationString)
Create a new BeanComparator. |
Method Summary | |
void |
addFirst(java.lang.String propertyName,
boolean descending)
Add a new property to be used first in the comparison. |
void |
addLast(java.lang.String propertyName,
boolean descending)
Add a new property to be used last in the comparison. |
void |
addOrToggle(java.lang.String propertyName)
Used to implement sorting similar to Windows Explorer. |
int |
compare(java.lang.Object a,
java.lang.Object b)
Compares its two arguments for order. |
static int |
compareObjects(java.lang.Object x,
java.lang.Object y)
|
static int |
compareObjects(java.lang.Object x,
java.lang.Object y,
boolean ignoreCase)
A utility method to compare two objects. |
boolean |
isIgnoreCase()
Getter for property ignoreCase. |
void |
remove(java.lang.String name)
Remove a property to use in the comparison |
void |
setIgnoreCase(boolean ignoreCase)
Setter for property ignoreCase. |
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()
public BeanComparator(java.lang.String configurationString)
"name,number"
will compare the
first on property name, and if the two values of name is equal the property
number will be compared.
configurationString
- The configuration StringMethod Detail |
public int compare(java.lang.Object a, java.lang.Object b)
Comparable.compareTo()
method. If the value of the property
is not a Comparable it is converted to a String (which is a Comrable) with
toString().
In comparisons null
is considered less than anything else
(and equal to null).
The value of a property is read with Beans.getProperty()
.
If all properties compare equal then 0 is returned. A special case
is when the BeanComparator has no fields added, then the comparison
is forwarded to the static method compareObjects.
compare
in interface java.util.Comparator
a
- The first bean to compareb
- The second bean to compare
public void addOrToggle(java.lang.String propertyName)
propertyName
- The property namepublic void addFirst(java.lang.String propertyName, boolean descending)
propertyName
- The name of the property to sort ondescending
- Indicate if the compare order on the specified property
should be reversed. When used in a sorting the sorting will be descending
instead of ascending.public void addLast(java.lang.String propertyName, boolean descending)
propertyName
- The name of the propertydescending
- Indicate if the compare order on the specified property
should be reversed. When used in a sorting the sorting will be descending
instead of ascending.public static int compareObjects(java.lang.Object x, java.lang.Object y)
public void remove(java.lang.String name)
name
- The name of the property no longer to use when comparingpublic static int compareObjects(java.lang.Object x, java.lang.Object y, boolean ignoreCase)
x
- y
- ignoreCase
-
public boolean isIgnoreCase()
public void setIgnoreCase(boolean ignoreCase)
ignoreCase
- New value of property ignoreCase.
|
Copyright 2002 by aragost | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |