prefuse.util.collections
Class CompositeComparator<E>

java.lang.Object
  extended by prefuse.util.collections.CompositeComparator<E>
All Implemented Interfaces:
java.util.Comparator<E>

public class CompositeComparator<E>
extends java.lang.Object
implements java.util.Comparator<E>

Comparator that makes comparison using an ordered list of individual comparators;

Author:
jeffrey heer

Constructor Summary
CompositeComparator(boolean reverse, java.util.Comparator<? super E>... cmp)
          Creates a new CompositeComparator.
CompositeComparator(java.util.Comparator<? super E>... cmp)
          Creates a new CompositeComparator.
CompositeComparator(int size)
          Creates an empty CompositeComparator with the given capacity.
CompositeComparator(int size, boolean reverse)
          Creates an empty CompositeComparator with the given capacity.
 
Method Summary
 void add(java.util.Comparator<? super E> c)
          Adds an additional comparator to this composite.
 int compare(E o1, E o2)
           
 boolean remove(java.util.Comparator<? super E> c)
          Removes a comparator from this composite.
 
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

CompositeComparator

public CompositeComparator(int size)
Creates an empty CompositeComparator with the given capacity.

Parameters:
size - the starting capacity of this comparator

CompositeComparator

public CompositeComparator(int size,
                           boolean reverse)
Creates an empty CompositeComparator with the given capacity.

Parameters:
size - the starting capacity of this comparator
reverse - when true, reverses the sort order of the included comparators, when false, objects are sorted as usual

CompositeComparator

public CompositeComparator(java.util.Comparator<? super E>... cmp)
Creates a new CompositeComparator.

Parameters:
cmp - the constituent comparators of this composite

CompositeComparator

public CompositeComparator(boolean reverse,
                           java.util.Comparator<? super E>... cmp)
Creates a new CompositeComparator.

Parameters:
cmp - the constituent comparators of this composite
reverse - when true, reverses the sort order of the included comparators, when false, objects are sorted as usual
Method Detail

add

public void add(java.util.Comparator<? super E> c)
Adds an additional comparator to this composite.

Parameters:
c - the Comparator to add

remove

public boolean remove(java.util.Comparator<? super E> c)
Removes a comparator from this composite.

Parameters:
c - the Comparator to remove
Returns:
true if the comparator was successfully removed, false otherwise

compare

public int compare(E o1,
                   E o2)
Specified by:
compare in interface java.util.Comparator<E>
See Also:
Comparator.compare(java.lang.Object, java.lang.Object)


Copyright © 2008 Regents of the University of California