org.norther.tammi.acorn.util
Class PropertyComparator

java.lang.Object
  extended by org.norther.tammi.acorn.util.PropertyComparator
All Implemented Interfaces:
Serializable, Comparator<Object>
Direct Known Subclasses:
VariableComparator

public class PropertyComparator
extends Object
implements Comparator<Object>, Serializable

A comparator for properties.

Version:
$Id: PropertyComparator.java,v 1.11 2009/09/28 15:08:49 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
PropertyComparator(String prop)
          Constructs a new comparator.
PropertyComparator(String[] props)
          Constructs a new comparator for multiple properties.
PropertyComparator(String[] props, Comparator<?> comp)
          Constructs a new comparator for multiple properties with a value comparator.
PropertyComparator(String prop, Comparator<?> comp)
          Constructs a new comparator with a value comparator.
 
Method Summary
 int compare(Object obj1, Object obj2)
           
protected  int compare(Object var1, Object var2, String prop)
          Compares the specified property of two objects in ascending order.
protected  Object getNestedProperty(Object obj, String prop)
          Gets the optionally nested property value.
protected  Object getProperty(Object obj, String prop)
          Gets the named property value.
 
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

PropertyComparator

public PropertyComparator(String prop)
Constructs a new comparator.

Parameters:
prop - the property to compare.

PropertyComparator

public PropertyComparator(String prop,
                          Comparator<?> comp)
Constructs a new comparator with a value comparator.

Parameters:
prop - the property to compare.
comp - the property value comparator.

PropertyComparator

public PropertyComparator(String[] props)
Constructs a new comparator for multiple properties.

Parameters:
props - the properties to compare.

PropertyComparator

public PropertyComparator(String[] props,
                          Comparator<?> comp)
Constructs a new comparator for multiple properties with a value comparator.

Parameters:
props - the properties to compare.
comp - the property value comparator.
Method Detail

compare

public int compare(Object obj1,
                   Object obj2)
Specified by:
compare in interface Comparator<Object>

compare

protected int compare(Object var1,
                      Object var2,
                      String prop)
Compares the specified property of two objects in ascending order.

Parameters:
var1 - the first object to be compared.
var2 - the second object to be compared.
prop - the name of the property.
Returns:
-1, 0 or 1 based on comparison.

getNestedProperty

protected Object getNestedProperty(Object obj,
                                   String prop)
                            throws Exception
Gets the optionally nested property value.

Parameters:
obj - the object.
prop - the property.
Returns:
the value or null.
Throws:
Exception - on errors.

getProperty

protected Object getProperty(Object obj,
                             String prop)
                      throws Exception
Gets the named property value.

Parameters:
obj - the object.
prop - the property.
Returns:
the value or null.
Throws:
Exception - on errors.


Copyright © 2004 The Norther Organization. All rights reserved.