org.clazzes.util.comparators
Class POJOFieldComparator

java.lang.Object
  extended by org.clazzes.util.comparators.POJOFieldComparator
All Implemented Interfaces:
java.util.Comparator

public class POJOFieldComparator
extends java.lang.Object
implements java.util.Comparator

This comparator compares a POJO by the value of the supplied property.

Author:
wglas

Constructor Summary
POJOFieldComparator(java.lang.Class clazz, java.lang.String property, java.util.Comparator fieldComparator)
          Contructs a field comparator, which compare POJOs by the value of the given property name using the given Comparator.
POJOFieldComparator(java.lang.Class clazz, java.lang.String property, ComparatorFactory comparatorFactory)
          Contructs a field comparator, which comparea POJOs by the value of the given property name and the comparator constructed using the given ComparatorFactory.
POJOFieldComparator(FieldAccessor fieldAccessor, java.util.Comparator fieldComparator)
          Contructs a field comparator, which uses the given accessor and Comparator.
POJOFieldComparator(FieldAccessor fieldAccessor, ComparatorFactory comparatorFactory)
          Contructs a field comparator, which uses the given accessor and constructs the comparator for the field using the given ComparatorFactory.
 
Method Summary
 int compare(java.lang.Object a, java.lang.Object b)
           
 FieldAccessor getFieldAccessor()
           
 java.util.Comparator getFieldComparator()
           
 void setFieldAccessor(FieldAccessor fieldAccessor)
           
 void setFieldComparator(java.util.Comparator fieldComparator)
           
 
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

POJOFieldComparator

public POJOFieldComparator(FieldAccessor fieldAccessor,
                           java.util.Comparator fieldComparator)
Contructs a field comparator, which uses the given accessor and Comparator.

Parameters:
fieldAccessor - The field accessor, which is used to fetch field values.
fieldComparator - The comparator, which compares field values.

POJOFieldComparator

public POJOFieldComparator(FieldAccessor fieldAccessor,
                           ComparatorFactory comparatorFactory)
Contructs a field comparator, which uses the given accessor and constructs the comparator for the field using the given ComparatorFactory.

Parameters:
fieldAccessor - The field accessor, which is used to fetch field values.
comparatorFactory - The factory used to create a comparator base d on the type of the field.

POJOFieldComparator

public POJOFieldComparator(java.lang.Class clazz,
                           java.lang.String property,
                           java.util.Comparator fieldComparator)
                    throws java.lang.SecurityException,
                           java.lang.NoSuchMethodException
Contructs a field comparator, which compare POJOs by the value of the given property name using the given Comparator.

Parameters:
clazz - The POJO clazz.
property - The name of the POJO property, for which we use the getter function.
fieldComparator - The underlying comparator.
Throws:
java.lang.SecurityException - If the security comtext does not allow acces to the getter.
java.lang.NoSuchMethodException - If the geter method does not exist.
See Also:
POJOFieldAccessor.POJOFieldAccessor(Class, String)

POJOFieldComparator

public POJOFieldComparator(java.lang.Class clazz,
                           java.lang.String property,
                           ComparatorFactory comparatorFactory)
                    throws java.lang.SecurityException,
                           java.lang.NoSuchMethodException
Contructs a field comparator, which comparea POJOs by the value of the given property name and the comparator constructed using the given ComparatorFactory.

Parameters:
clazz - The POJO clazz.
property - The name of the POJO property, for which we use the getter function.
comparatorFactory - The factory used to create a comparator base d on the type of the field.
Throws:
java.lang.SecurityException - If the security comtext does not allow acces to the getter.
java.lang.NoSuchMethodException - If the geter method does not exist.
See Also:
POJOFieldAccessor.POJOFieldAccessor(Class, String)
Method Detail

compare

public int compare(java.lang.Object a,
                   java.lang.Object b)
Specified by:
compare in interface java.util.Comparator

getFieldAccessor

public FieldAccessor getFieldAccessor()
Returns:
the fieldAccessor

setFieldAccessor

public void setFieldAccessor(FieldAccessor fieldAccessor)
Parameters:
fieldAccessor - the fieldAccessor to set

getFieldComparator

public java.util.Comparator getFieldComparator()
Returns:
the fieldComparator

setFieldComparator

public void setFieldComparator(java.util.Comparator fieldComparator)
Parameters:
fieldComparator - the fieldComparator to set


Copyright © 2009. All Rights Reserved.