public class BeanComparatorAdapter
extends java.lang.Object
implements java.util.Comparator
Comparator able to compare bean objects,
to a Comparator able to compare nodes based on those bean objects.
The nodes will be sorted as the underlying bean objects are sorted by the bean comparator passed in the constructor of this object.
A typical use of the BeanComparatorAdapter will be inside a ChildrenManager.
The method getComparator() must return a Comparator that compares
nodes. But as a user you may prefer to compare at the bean level as each node
represents a given bean. You can therefore write a Comparator that compares your
beans and use the BeanComparatorAdapter to return a node Comparator
based on your bean Comparator :
public Comparator getComparator() {
return new BeanComparatorAdapter(new MyBeanComparator());
}
In this example, MyBeanComparator is a class that you write to compare
the beans that are used to create the node. MyBeanComparator only knows
how to compare two bean objects, instead of comparing two nodes based on those bean objects.
| Constructor and Description |
|---|
BeanComparatorAdapter(java.util.Comparator beanComparator)
Creates a new GPBeanNode based on the given bean with no children
The new node is therefore a leaf.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(java.lang.Object o1,
java.lang.Object o2) |
boolean |
equals(java.lang.Object obj) |
public BeanComparatorAdapter(java.util.Comparator beanComparator)
public final int compare(java.lang.Object o1,
java.lang.Object o2)
compare in interface java.util.Comparatorpublic final boolean equals(java.lang.Object obj)
equals in interface java.util.Comparatorequals in class java.lang.Object