org.ow2.jonas.webapp.jonasadmin.common
Class BeanComparator

java.lang.Object
  extended by org.ow2.jonas.webapp.jonasadmin.common.BeanComparator
All Implemented Interfaces:
Comparator

public class BeanComparator
extends Object
implements Comparator

BeanComparator is a comparator for beans. It's used to compare a bean with its own properties or with its own string value (return by the toString() method).

Author:
Michel-Ange ANTON

Constructor Summary
BeanComparator()
          Comparator by default (use the toString() methods).
BeanComparator(String[] p_Orders)
          Comparator in order of the properties.
 
Method Summary
 int compare(Object p_O1, Object p_O2)
          Compare two beans instances.
protected  int compareDefault(Object p_O1, Object p_O2)
          Compare the beans like a string (used the toString() method of the object).
static int compareNull(Object p_O1, Object p_O2)
          Compare the null of two objects.
protected  int compareOrder(Object p_O1, Object p_O2)
          Compare the beans with the properties in order given.
static int compareString(String p_S1, String p_S2)
          Compare two strings with the ignore case but if is identical, compare normaly with case.
 boolean equals(Object p_Obj)
          Indentical bean.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanComparator

public BeanComparator()
Comparator by default (use the toString() methods).


BeanComparator

public BeanComparator(String[] p_Orders)
Comparator in order of the properties.

Parameters:
p_Orders - A array of the names of the properties
Method Detail

compare

public int compare(Object p_O1,
                   Object p_O2)
Compare two beans instances.

Specified by:
compare in interface Comparator
Parameters:
p_O1 - The first bean to compare
p_O2 - The second bean to compare
Returns:
0 if equals, < 0 if first bean lower than second bean, > 0 if first bean upper than second bean.

equals

public boolean equals(Object p_Obj)
Indentical bean.

Specified by:
equals in interface Comparator
Overrides:
equals in class Object
Parameters:
p_Obj - The bean to compare.
Returns:
True if identical.

compareNull

public static int compareNull(Object p_O1,
                              Object p_O2)
Compare the null of two objects.

Parameters:
p_O1 - The first object to compare
p_O2 - The second object to compare
Returns:
0 if the two are null or the two not null, < 0 if second object is null, > 0 if first object is null.

compareString

public static int compareString(String p_S1,
                                String p_S2)
Compare two strings with the ignore case but if is identical, compare normaly with case.

Parameters:
p_O1 - The first string to compare
p_O2 - The second string to compare
Returns:
0 if equals, < 0 if first string lower than second string, > 0 if first string upper than second string.

compareDefault

protected int compareDefault(Object p_O1,
                             Object p_O2)
Compare the beans like a string (used the toString() method of the object). Used when order is unknown.

Parameters:
p_O1 - The first bean to compare
p_O2 - The second bean to compare
Returns:
0 if equals, < 0 if first bean lower than second bean, > 0 if first bean upper than second bean.

compareOrder

protected int compareOrder(Object p_O1,
                           Object p_O2)
Compare the beans with the properties in order given. Used when order is known.

Parameters:
p_O1 - The first bean to compare
p_O2 - The second bean to compare
Returns:
0 if equals, < 0 if first bean lower than second bean, > 0 if first bean upper than second bean.


Copyright © 2010 OW2 Consortium. All Rights Reserved.