org.knowceans.map
Class CategoryMap<T>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<T,java.lang.Integer>
          extended by org.knowceans.map.CategoryMap<T>
Type Parameters:
T -
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<T,java.lang.Integer>

public class CategoryMap<T>
extends java.util.HashMap<T,java.lang.Integer>

map that allows to cumulate entries of type T, keeping track of frequencies and id values.

TODO: remove() not handling ids internally, and any new element is created using the size of the category map as an id.

Author:
gregor
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
CategoryMap()
           
 
Method Summary
 int add(T element)
          add one point to the element, returning an integer id of the category of the element.
 void clear()
           
 java.lang.Integer getCategory(T key)
          gets the numerical category value for this element (whereas the get() method returns the bin count.)
 java.lang.Integer put(T key, java.lang.Integer value)
           
 void putAll(java.util.Map<? extends T,? extends java.lang.Integer> m)
           
 java.lang.Integer remove(java.lang.Object key)
          Note: does not remove element to preserve id integrity.
 int subtract(T element)
          subtract one point to the element.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, 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

CategoryMap

public CategoryMap()
Method Detail

add

public int add(T element)
add one point to the element, returning an integer id of the category of the element.

Parameters:
element -
Returns:
category of element

subtract

public int subtract(T element)
subtract one point to the element. If the result is zero, the element is not removed

Parameters:
element -
Returns:
category of the element

put

public java.lang.Integer put(T key,
                             java.lang.Integer value)
Specified by:
put in interface java.util.Map<T,java.lang.Integer>
Overrides:
put in class java.util.HashMap<T,java.lang.Integer>

putAll

public void putAll(java.util.Map<? extends T,? extends java.lang.Integer> m)
Specified by:
putAll in interface java.util.Map<T,java.lang.Integer>
Overrides:
putAll in class java.util.HashMap<T,java.lang.Integer>

remove

public java.lang.Integer remove(java.lang.Object key)
Note: does not remove element to preserve id integrity. Use clear() and rebuild the map.

Specified by:
remove in interface java.util.Map<T,java.lang.Integer>
Overrides:
remove in class java.util.HashMap<T,java.lang.Integer>

clear

public void clear()
Specified by:
clear in interface java.util.Map<T,java.lang.Integer>
Overrides:
clear in class java.util.HashMap<T,java.lang.Integer>

getCategory

public java.lang.Integer getCategory(T key)
gets the numerical category value for this element (whereas the get() method returns the bin count.)

Parameters:
key -
Returns: