org.apache.commons.beanutils
Class BeanComparator
java.lang.Object
|
+--org.apache.commons.beanutils.BeanComparator
- All Implemented Interfaces:
- java.util.Comparator, java.io.Serializable
- public class BeanComparator
- extends java.lang.Object
- implements java.util.Comparator, java.io.Serializable
Allows you to pass the name of a method in and compare two beans.
- Author:
- Eric Pugh
- See Also:
- Serialized Form
Constructor Summary |
BeanComparator(java.lang.String property)
Creates a Bean comparator that calls the property specified
on the objects. |
BeanComparator(java.lang.String property,
java.util.Comparator comparator)
Creates a comparator that compares objects based on the method
name of two JavaBeans. |
Method Summary |
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compare two JavaBeans by their shared property. |
java.util.Comparator |
getComparator()
Gets the Comparator being used to compare beans. |
java.lang.String |
getProperty()
Gets the property attribute of the BeanComparator |
void |
setProperty(java.lang.String property)
Sets the method to be called to compare two JavaBeans |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
equals |
property
private java.lang.String property
comparator
private java.util.Comparator comparator
BeanComparator
public BeanComparator(java.lang.String property)
- Creates a Bean comparator that calls the property specified
on the objects.
If you pass in a null, the BeanComparator defaults to comparing
based on the natural order, that is java.lang.Comparable.
- Parameters:
property
- String name of bean property
BeanComparator
public BeanComparator(java.lang.String property,
java.util.Comparator comparator)
- Creates a comparator that compares objects based on the method
name of two JavaBeans.
- Parameters:
property
- String method name to call to comparecomparator
- Comparator to call afterwords!
setProperty
public void setProperty(java.lang.String property)
- Sets the method to be called to compare two JavaBeans
- Parameters:
property
- String method name to call to compare
getProperty
public java.lang.String getProperty()
- Gets the property attribute of the BeanComparator
- Returns:
- String method name to call to compare
getComparator
public java.util.Comparator getComparator()
- Gets the Comparator being used to compare beans.
compare
public int compare(java.lang.Object o1,
java.lang.Object o2)
- Compare two JavaBeans by their shared property.
- Specified by:
compare
in interface java.util.Comparator
- Parameters:
o1
- Object The first bean to get data from to compare againsto2
- Object The second bean to get data from to compare- Returns:
- int negative or positive based on order
Copyright (c) 2001-2003 - Apache Software Foundation