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

java.lang.Object
  extended by edu.mit.jmwe.util.AbstractIndexComparator<T,T>
      extended by edu.mit.jmwe.util.ListComparator<T>
Type Parameters:
T - the token type
All Implemented Interfaces:
Comparator<T>

public class ListComparator<T>
extends AbstractIndexComparator<T,T>

Compares two elements from a list based on their order of appearance in the list. Returns a negative integer, zero, or a positive integer if the first argument is appears earlier than, is equal to, or after the second.

Since:
jMWE 1.0.0
Version:
$Id: ListComparator.java 558 2011-05-05 19:23:28Z markaf $
Author:
N. Kulkarni, M.A. Finlayson

Field Summary
 
Fields inherited from class edu.mit.jmwe.util.AbstractIndexComparator
indexMap
 
Constructor Summary
ListComparator(List<T> list)
          Constructs the comparator from the given list of objects by mapping each object in the list to its index in the list.
ListComparator(Map<T,Integer> indexMap)
          Constructs the comparator from the given index map of each object in a list to its index in the list.
 
Method Summary
 int compare(T arg0, T arg1)
           
 
Methods inherited from class edu.mit.jmwe.util.AbstractIndexComparator
createIndexMap, getIndexMap
 
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

ListComparator

public ListComparator(List<T> list)
Constructs the comparator from the given list of objects by mapping each object in the list to its index in the list.

Parameters:
list - the list of objects used to construct this comparator. May not be null.
Throws:
NullPointerException - if the given list is null
Since:
jMWE 1.0.0

ListComparator

public ListComparator(Map<T,Integer> indexMap)
Constructs the comparator from the given index map of each object in a list to its index in the list.

Parameters:
indexMap - map of each object in a list to its index in the list. May not be null.
Throws:
NullPointerException - if the specified map is null
Since:
jMWE 1.0.0
Method Detail

compare

public int compare(T arg0,
                   T arg1)


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