com.samskivert.util
Class CountHashMap<K>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,int[]>
          extended by com.samskivert.util.CountHashMap<K>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,int[]>

public class CountHashMap<K>
extends HashMap<K,int[]>

A hashmap that maintains a count for each key. This implementation should change so that we extend AbstractMap, do our own hashing, and can use our own Entry class.

See Also:
Serialized Form

Nested Class Summary
protected static class CountHashMap.CountEntryImpl<K>
           
protected  class CountHashMap.CountEntrySet<E>
           
static interface CountHashMap.Entry<K>
           
 
Constructor Summary
CountHashMap()
           
 
Method Summary
 void compress()
          Compress the count map- remove entries for which the value is 0.
 Set<CountHashMap.Entry<K>> countEntrySet()
          Returns a set of CountHashMap.Entry records which can be used to easily obtain our count.
 Set<Map.Entry<K,int[]>> entrySet()
           
 int getCount(K key)
          Get the count associated with the specified key.
 int getTotalCount()
          Get the total count for all keys in the map.
 int incrementCount(K key, int amount)
          Increment the value associated with the specified key, return the new value.
 int setCount(K key, int count)
          Set the count for the specified key.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, 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

CountHashMap

public CountHashMap()
Method Detail

incrementCount

public int incrementCount(K key,
                          int amount)
Increment the value associated with the specified key, return the new value.


getCount

public int getCount(K key)
Get the count associated with the specified key.


setCount

public int setCount(K key,
                    int count)
Set the count for the specified key.

Returns:
the old count.

getTotalCount

public int getTotalCount()
Get the total count for all keys in the map.


compress

public void compress()
Compress the count map- remove entries for which the value is 0.


entrySet

public Set<Map.Entry<K,int[]>> entrySet()
Specified by:
entrySet in interface Map<K,int[]>
Overrides:
entrySet in class HashMap<K,int[]>

countEntrySet

public Set<CountHashMap.Entry<K>> countEntrySet()
Returns a set of CountHashMap.Entry records which can be used to easily obtain our count.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.