dsto.dfc.databeans
Class CategorySorter<T>

java.lang.Object
  extended by dsto.dfc.databeans.CategorySorter<T>
All Implemented Interfaces:
ISorter<T>, Comparator<T>

public abstract class CategorySorter<T>
extends Object
implements ISorter<T>

A sorter that makes it easier when sorting items in category, value order. Subclasses define numeric categories for values that are used as the first order sorting criteria. Values for equal categories are sorted by value as usual.

Author:
Matthew Phillips

Field Summary
 
Fields inherited from interface dsto.dfc.databeans.ISorter
DEFAULT_SORTER, NULL_SORTER
 
Constructor Summary
CategorySorter()
           
 
Method Summary
abstract  boolean affectsOrder(PropertyPath path)
          Return true if a change to a given path might affect the sort order of the object at the root of the path.
protected abstract  int category(T item)
          Generate a numeric category for a given item.
 int compare(T o1, T o2)
          See Comparator.compare(Object, Object).
protected abstract  int compareValues(T item1, T item2)
          Compare two values that are in the same category.
 
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

CategorySorter

public CategorySorter()
Method Detail

compare

public int compare(T o1,
                   T o2)
Description copied from interface: ISorter
See Comparator.compare(Object, Object).

Specified by:
compare in interface ISorter<T>
Specified by:
compare in interface Comparator<T>

affectsOrder

public abstract boolean affectsOrder(PropertyPath path)
Description copied from interface: ISorter
Return true if a change to a given path might affect the sort order of the object at the root of the path. This is an opportunity for optimization: simply returning true will work at the cost of some wasted ovehead.

Specified by:
affectsOrder in interface ISorter<T>

compareValues

protected abstract int compareValues(T item1,
                                     T item2)
Compare two values that are in the same category. This will usually be the same as compare(Object, Object) in a non-category sorter.


category

protected abstract int category(T item)
Generate a numeric category for a given item. Items are sorted in category, value order.



Copyright © 2008 Commonwealth of Australia