edu.nrao.sss.sort
Class CompoundComparator<T>

java.lang.Object
  extended by edu.nrao.sss.sort.CompoundComparator<T>
All Implemented Interfaces:
Comparator<T>

public class CompoundComparator<T>
extends Object
implements Comparator<T>

A comparator that is a chain of other comparators.

The first comparator in this one's list functions as the primary key, the next as a secondary key (in case of a tie in primary keys), and so on.

Rather than wrapping its internal list, this comparator provides its list of components for its clients to access directly.

Version Info:

$Revision: 593 $
$Date: 2007-05-07 15:54:14 -0600 (Mon, 07 May 2007) $
$Author: dharland $

Since:
2007-05-03
Author:
David M. Harland

Constructor Summary
CompoundComparator()
          Creates a new instance with no contained comparators.
CompoundComparator(Collection<? extends Comparator<T>> newComparators)
          Creates a new compound comparator with the given elements.
CompoundComparator(Comparator<T>... newComparators)
          Creates a new compound comparator with the given elements.
 
Method Summary
 int compare(T o1, T o2)
           
 List<Comparator<T>> getComponents()
          Returns the list of component comparators held by this one.
 
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

CompoundComparator

public CompoundComparator()
Creates a new instance with no contained comparators.


CompoundComparator

public CompoundComparator(Comparator<T>... newComparators)
Creates a new compound comparator with the given elements. The constituent comparators are placed onto this one in the same order they are given to this constructor.

Parameters:
newComparators - the comparators held by this one.

CompoundComparator

public CompoundComparator(Collection<? extends Comparator<T>> newComparators)
Creates a new compound comparator with the given elements. The constituent comparators are placed onto this one in the same order they inhabit in the given collection.

Parameters:
newComparators - the comparators held by this one.
Method Detail

getComponents

public List<Comparator<T>> getComponents()
Returns the list of component comparators held by this one.

The returned list is the one actually held by this comparator. Clients who wish to add, remove, or otherwise manipulate the components, or their status in the list, should work directly with this list.

Returns:
the list of component comparators held by this one.

compare

public int compare(T o1,
                   T o2)
Specified by:
compare in interface Comparator<T>


Copyright © 2009. All Rights Reserved.