org.clazzes.util.comparators
Class POJOComparatorFactory

java.lang.Object
  extended by org.clazzes.util.comparators.POJOComparatorFactory

public class POJOComparatorFactory
extends java.lang.Object

This factory contructs a comparator for a POJO class by parsing an expression.

Author:
wglas

Constructor Summary
POJOComparatorFactory()
          Contruct a POJOComparatorFactory using an instance of DefaultComparatorFactory.
POJOComparatorFactory(ComparatorFactory comparatorFactory)
          Contruct a POJOComparatorFactory using the given comparator factory for constructing value comparators.
POJOComparatorFactory(java.util.Locale locale)
          Contruct a POJOComparatorFactory using an instance of LocalizedComparatorFactory
 
Method Summary
 java.util.Comparator getComparator(java.lang.Class clazz, java.lang.String expression, boolean ascending)
          Construct a comparator for the given class by evaluating the specified chain of properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

POJOComparatorFactory

public POJOComparatorFactory()
Contruct a POJOComparatorFactory using an instance of DefaultComparatorFactory.

Parameters:
comparatorFactory - The factory, which constructs comparators for individual property values.

POJOComparatorFactory

public POJOComparatorFactory(java.util.Locale locale)
Contruct a POJOComparatorFactory using an instance of LocalizedComparatorFactory

Parameters:
comparatorFactory - The factory, which constructs comparators for individual property values.

POJOComparatorFactory

public POJOComparatorFactory(ComparatorFactory comparatorFactory)
Contruct a POJOComparatorFactory using the given comparator factory for constructing value comparators.

Parameters:
comparatorFactory - The factory, which constructs comparators for individual property values.
Method Detail

getComparator

public java.util.Comparator getComparator(java.lang.Class clazz,
                                          java.lang.String expression,
                                          boolean ascending)
                                   throws InvalidExpressionSyntaxException
Construct a comparator for the given class by evaluating the specified chain of properties.

Parameters:
clazz - The class of the POJO object, which will be compared by the returned comparator.
expression - An expression, which represnets an OGNL-like chain of properties like the following examples:
  • myProperty
  • Compare x.getMyProperty() by y.getMyProperty().
  • myProperty.abc
  • Compare x.getMyProperty().getAbc() by y.getMyProperty().getAbc().
  • {abc|cde|ghi}
  • Lexicographically compare the values of abc, def and ghi. The first property is the most significant.
  • prop.{abc|cde|ghi}
  • Lexicographically compare the values of prop.abc, prop.def and gprop.hi.
Each component may be preceded by a minus sign in order to invert the sort order:
  • -prop
  • Reverse compare the values of prop.
  • -{abc|-cde|ghi}
  • Lexicographically reverse compare the values of abc, -def and ghi. The first property is the most significant.
ascending - If false, his parameter my be used to invert the sort oder of the returned comparator.
Returns:
An comparator for the given POJO class using the given expression.
Throws:
InvalidExpressionSyntaxException - If the syntax of the expression is invalid.


Copyright © 2009. All Rights Reserved.