org.apache.shale.usecases.rolodex
Class GenericComparator

java.lang.Object
  extended by org.apache.shale.usecases.rolodex.GenericComparator
All Implemented Interfaces:
Comparator

public class GenericComparator
extends Object
implements Comparator

Generic comparator that uses a list of property names to compare the state of two objects using the reflection API. The property names are passed via a comma delimited. The collating sequence is determined by the sortAcending attribute.


Field Summary
static Log log
          Common logger utility.
protected  List sortBy
          Holds an array of property names in the target object that will be use to compare the two objects.
 
Constructor Summary
GenericComparator()
           
 
Method Summary
 int compare(Object o1, Object o2)
          Compares the property names in the sortBy list with the target sortable objects.
 boolean getSortAscending()
          Returns true if the collection should be sorted ascending by the sortBy properties list.
 String getSortBy()
          Returns a comma delimited list of property names used to compare two objects.
 void setSortAscending(boolean value)
          Sets the sequence the collection should be sorted.
 void setSortBy(String properties)
          Passed a comma delimited list of property names to compare two object by.
 
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

log

public static Log log

Common logger utility.


sortBy

protected List sortBy

Holds an array of property names in the target object that will be use to compare the two objects.

Constructor Detail

GenericComparator

public GenericComparator()
Method Detail

getSortAscending

public boolean getSortAscending()

Returns true if the collection should be sorted ascending by the sortBy properties list.


setSortAscending

public void setSortAscending(boolean value)

Sets the sequence the collection should be sorted. A true will result in sort ascending.


setSortBy

public void setSortBy(String properties)

Passed a comma delimited list of property names to compare two object by.


getSortBy

public String getSortBy()

Returns a comma delimited list of property names used to compare two objects.


compare

public int compare(Object o1,
                   Object o2)

Compares the property names in the sortBy list with the target sortable objects. The collating sequence is determined by the sortAcending attribute.

Specified by:
compare in interface Comparator
Parameters:
o1 - - target object 1
o2 - - target object 2
Returns:
- integer value representing the comparison of the two objects key properties.


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.