com.aliasi.util
Class ObjectToDoubleMap<E>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<E,Double>
          extended by com.aliasi.util.ObjectToDoubleMap<E>
Type Parameters:
E - the type of keys for this map
All Implemented Interfaces:
Serializable, Cloneable, Map<E,Double>

public class ObjectToDoubleMap<E>
extends HashMap<E,Double>

An ObjectToDoubleMap maintains a mapping from objects to double-valued counters, which may be incremented or set. Objects not in the underlying map's key set are assumed to have value 0.0. Thus incrementing an object that is not currently set is equivalent to setting it to the increment value.

Since:
LingPipe2.3.1
Version:
3.9.1
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
ObjectToDoubleMap()
          Construct an object to double mapping.
ObjectToDoubleMap(int initialCapacity)
          Construct an object to double mapping with the specified initial capacity.
 
Method Summary
 double getValue(E key)
          Returns the value of the specified key in the map.
 void increment(E key, double increment)
          Increment the value of the specified key by the specified increment amount.
 Object[] keysOrderedByValue()
          Deprecated. Use keysOrderedByValueList() instead.
 List<E> keysOrderedByValueList()
          Returns the list of keys ordered in decreasing order of value.
 ScoredObject<E>[] scoredObjectsOrderedByValue()
          Deprecated. Use scoredObjectsOrderedByValueList() instead.
 List<ScoredObject<E>> scoredObjectsOrderedByValueList()
          Returns a list of scored objects corresponding to the entries in decreasing order of value.
 void set(E key, double val)
          Sets the specified key to the specified value.
 Comparator<E> valueComparator()
          Returns the comparator that compares objects based on their values.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ObjectToDoubleMap

public ObjectToDoubleMap()
Construct an object to double mapping.


ObjectToDoubleMap

public ObjectToDoubleMap(int initialCapacity)
Construct an object to double mapping with the specified initial capacity.

Parameters:
initialCapacity - Initial capacity of the map.
Method Detail

increment

public void increment(E key,
                      double increment)
Increment the value of the specified key by the specified increment amount. If the key is not currently in the key set, it is added and set to the increment amount.

Parameters:
key - Object to increment.
increment - Increment amount.

set

public void set(E key,
                double val)
Sets the specified key to the specified value.

Parameters:
key - Object to set.
val - New value for the object.

getValue

public double getValue(E key)
Returns the value of the specified key in the map. If the key is not in the key set, the return value is 0.0.

Parameters:
key - Object whose value is returned.
Returns:
Value of specified key.

keysOrderedByValueList

public List<E> keysOrderedByValueList()
Returns the list of keys ordered in decreasing order of value.

Returns:
Key list with keys in decreasing order of value.

keysOrderedByValue

@Deprecated
public Object[] keysOrderedByValue()
Deprecated. Use keysOrderedByValueList() instead.

Returns the array of keys ordered in decreasing order of value.

Returns:
Keys in decreasing order of value.

scoredObjectsOrderedByValueList

public List<ScoredObject<E>> scoredObjectsOrderedByValueList()
Returns a list of scored objects corresponding to the entries in decreasing order of value.

Returns:
Scored object list in decreasing order of value.

scoredObjectsOrderedByValue

@Deprecated
public ScoredObject<E>[] scoredObjectsOrderedByValue()
Deprecated. Use scoredObjectsOrderedByValueList() instead.

Returns an array of scored objects corresponding to the entries in this map in decreasing order of value.

Returns:
Scored objects in decreasing order of value.

valueComparator

public Comparator<E> valueComparator()
Returns the comparator that compares objects based on their values. If the objects being compared have the same value, then the return result depends on their objects. If the objects are comparable, their natural ordering is returned. If they are not comparable, the result is 0, so they are treated as equal. Not-a-number values are considered smaller than any other numbers for the purpose of this ordering.

Returns:
The comparator that sorts according to score.