edu.mit.jmwe.util
Class AbstractIndexComparator<T,C>

java.lang.Object
  extended by edu.mit.jmwe.util.AbstractIndexComparator<T,C>
Type Parameters:
T - the type of the tokens that are indexed
C - the type of the object being compared
All Implemented Interfaces:
Comparator<C>
Direct Known Subclasses:
ListComparator, MWEComparator

public abstract class AbstractIndexComparator<T,C>
extends Object
implements Comparator<C>

Base class for constructing a Comparator from a map of tokens in a list to their positions in the list. Subclasses are comparators that compare objects that consist of these tokens by using the tokens' indices.

Since:
jMWE 1.0.0
Version:
$Id: AbstractIndexComparator.java 554 2011-05-05 19:19:15Z markaf $
Author:
M.A. Finlayson

Field Summary
protected  Map<T,Integer> indexMap
           
 
Constructor Summary
AbstractIndexComparator(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.
AbstractIndexComparator(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
static
<T> Map<T,Integer>
createIndexMap(List<T> list)
          Returns a map of each object in the list mapped to its index in the list.
 Map<T,Integer> getIndexMap()
          Returns the index map on which this comparator is based.
 
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
compare, equals
 

Field Detail

indexMap

protected final Map<T,Integer> indexMap
Constructor Detail

AbstractIndexComparator

public AbstractIndexComparator(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

AbstractIndexComparator

public AbstractIndexComparator(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

getIndexMap

public Map<T,Integer> getIndexMap()
Returns the index map on which this comparator is based.

Returns:
the non-null index map on which this comparator is based.
Since:
jMWE 1.0.0

createIndexMap

public static <T> Map<T,Integer> createIndexMap(List<T> list)
Returns a map of each object in the list mapped to its index in the list.

Type Parameters:
T - the type of objects in the sentence
Parameters:
list - a non-null list
Returns:
a map of each object in the list mapped to its index in the list
Throws:
NullPointerException - if the given list is null.
Since:
jMWE 1.0.0


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