edu.mit.jmwe.util
Class CompositeComparator<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<Comparator<T>>
          extended by edu.mit.jmwe.util.CompositeComparator<T>
All Implemented Interfaces:
Iterable<Comparator<T>>, Collection<Comparator<T>>, Comparator<T>, List<Comparator<T>>

public class CompositeComparator<T>
extends AbstractList<Comparator<T>>
implements Comparator<T>, List<Comparator<T>>

A comparator constructed out of multiple comparators.

Since:
jMWE 1.0.0
Version:
$Id: CompositeComparator.java 610 2011-05-06 20:05:20Z markaf $
Author:
M.A. Finlayson

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
CompositeComparator(Comparator<T>... cs)
          Constructs a composite comparator from an array of comparators.
CompositeComparator(Comparator<T> one, Comparator<T> two)
          Constructs a composite comparator from two of comparators.
CompositeComparator(Comparator<T> one, Comparator<T> two, Comparator<T> three)
          Constructs a composite comparator from three of comparators.
CompositeComparator(List<? extends Comparator<T>> cs)
          Constructs a composite comparator from an array of comparators.
 
Method Summary
 int compare(T one, T two)
           
 Comparator<T> get(int index)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, subList, toArray, toArray
 

Constructor Detail

CompositeComparator

public CompositeComparator(Comparator<T> one,
                           Comparator<T> two)
Constructs a composite comparator from two of comparators. The array of comparators should be ordered by descending preference. The most preferred comparator should be first, the second-most-preferred second, etc. The comparators may not be null

Throws:
NullPointerException - if any specified comparator null.
Since:
jMWE 1.0.0

CompositeComparator

public CompositeComparator(Comparator<T> one,
                           Comparator<T> two,
                           Comparator<T> three)
Constructs a composite comparator from three of comparators. The array of comparators should be ordered by descending preference. The most preferred comparator should be first, the second-most-preferred second, etc. The comparators may not be null

Throws:
NullPointerException - if any specified comparator null.
Since:
jMWE 1.0.0

CompositeComparator

public CompositeComparator(Comparator<T>... cs)
Constructs a composite comparator from an array of comparators. The array of comparators should be ordered by descending preference. The most preferred comparator should be first, the second-most-preferred second, etc.

Parameters:
cs - the array of comparators in order of descending preference. May not be null, nor contain null.
Throws:
NullPointerException - if the specified array is null or if any of its elements are null.
Since:
jMWE 1.0.0

CompositeComparator

public CompositeComparator(List<? extends Comparator<T>> cs)
Constructs a composite comparator from an array of comparators. The array of comparators should be ordered by descending preference. The most preferred comparator should be first, the second-most-preferred second, etc.

Parameters:
cs - the list of comparators in order of descending preference. May not be null, nor contain null.
Throws:
NullPointerException - if the specified array is null or if any of its elements are null.
Since:
jMWE 1.0.0
Method Detail

compare

public int compare(T one,
                   T two)
Specified by:
compare in interface Comparator<T>

get

public Comparator<T> get(int index)
Specified by:
get in interface List<Comparator<T>>
Specified by:
get in class AbstractList<Comparator<T>>

size

public int size()
Specified by:
size in interface Collection<Comparator<T>>
Specified by:
size in interface List<Comparator<T>>
Specified by:
size in class AbstractCollection<Comparator<T>>


Copyright © 2011 Massachusetts Institute of Technology. All Rights Reserved.