edu.umd.cloud9.util
Class Scorekeeper<K extends Comparable<K>,V extends Number & Comparable<V>>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by edu.umd.cloud9.util.Scorekeeper<K,V>
Type Parameters:
K - type of key
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
Histogram

public class Scorekeeper<K extends Comparable<K>,V extends Number & Comparable<V>>
extends HashMap<K,V>

An object that holds scores associated with each object (the key) and supports iteration by score (descending). Many applications call for this type of functionality, e.g., keeping track of the score of each document in an document retrieval application.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
Scorekeeper()
          Constructs a ScoreSortedMap.
 
Method Summary
 Map.Entry<K,V> getEntryByRank(int i)
          Returns the ith scoring entry.
 SortedSet<Map.Entry<K,V>> getSortedEntries()
          Returns the all entries sorted by scores.
 SortedSet<Map.Entry<K,V>> getSortedEntries(int n)
          Returns the n top entries sorted by scores.
 List<K> getSortedKeys()
          Returns a list of the keys, sorted by score.
 Map.Entry<K,V> getTopEntry()
          Returns the top-scoring entry.
 
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
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

Scorekeeper

public Scorekeeper()
Constructs a ScoreSortedMap.

Method Detail

getSortedEntries

public SortedSet<Map.Entry<K,V>> getSortedEntries()
Returns the all entries sorted by scores. Score ties are broken by the sort order of the key.

Returns:
a sorted set view of the entries sorted by scores

getSortedEntries

public SortedSet<Map.Entry<K,V>> getSortedEntries(int n)
Returns the n top entries sorted by scores. Score ties are broken by the sort order of the key.

Parameters:
n - number of entries to retrieve
Returns:
a Set view of the entries sorted by scores

getTopEntry

public Map.Entry<K,V> getTopEntry()
Returns the top-scoring entry.

Returns:
the top-scoring entry

getEntryByRank

public Map.Entry<K,V> getEntryByRank(int i)
Returns the ith scoring entry.

Parameters:
i - the rank
Returns:
the ith scoring entry

getSortedKeys

public List<K> getSortedKeys()
Returns a list of the keys, sorted by score.

Returns:
a list of the keys, sorted by score