bb.util
Class ReflectUtil.FieldComparator

java.lang.Object
  extended by bb.util.ReflectUtil.FieldComparator
All Implemented Interfaces:
Serializable, Comparator<Field>
Enclosing class:
ReflectUtil

public static class ReflectUtil.FieldComparator
extends Object
implements Comparator<Field>, Serializable

Imposes an ordering on Fields that is consistent with equals; see compare for details.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

See Also:
Serialized Form

Field Summary
private static ReflectUtil.FieldComparator instance
           
private static long serialVersionUID
           
 
Constructor Summary
ReflectUtil.FieldComparator()
           
 
Method Summary
 int compare(Field f1, Field f2)
           Tries to order f1 and f2 by their names (case irrelevant): returns f1.getName().toLowerCase().compareTo( f2.getName().toLowerCase() ) if that result is !
static ReflectUtil.FieldComparator getInstance()
          Since this class has no instance state, there is no point in creating multiple instances: one instance is the same as another, may be fully concurrently used, etc.
 
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
 

Field Detail

instance

private static final ReflectUtil.FieldComparator instance

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

ReflectUtil.FieldComparator

public ReflectUtil.FieldComparator()
Method Detail

getInstance

public static ReflectUtil.FieldComparator getInstance()
Since this class has no instance state, there is no point in creating multiple instances: one instance is the same as another, may be fully concurrently used, etc. So, for top performance, users should call this method instead of creating new instances.


compare

public final int compare(Field f1,
                         Field f2)
                  throws IllegalArgumentException,
                         IllegalStateException

Tries to order f1 and f2 by their names (case irrelevant): returns f1.getName().toLowerCase().compareTo( f2.getName().toLowerCase() ) if that result is != 0.

Else tries to order f1 and f2 by their class names: returns f1.getDeclaringClass().getName().compareTo( f2.getDeclaringClass().getName() ) if that result is != 0.

Else returns 0 if f1.equals(f2) is true. This is the only circumstance in which 0 will ever be returned, thus, this Comparator is consistent with equals (see Comparator for more discussion).

Else throws an IllegalStateException.

Specified by:
compare in interface Comparator<Field>
Throws:
IllegalArgumentException - if f1 or f2 is null
IllegalStateException - if run out of criteria to order f1 and f2