complex
Class IntegerTreeMap

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.TreeMap
          extended bycomplex.IntegerTreeMap
All Implemented Interfaces:
java.lang.Cloneable, IntegerMap, java.util.Map, java.io.Serializable, java.util.SortedMap

public class IntegerTreeMap
extends java.util.TreeMap
implements IntegerMap

A simple implementation of an IntegerMap, using a TreeMap with value-type Integer.

Author:
karsten
See Also:
IntegerMap, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.TreeMap
 
Nested classes inherited from class java.util.AbstractMap
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
 
Fields inherited from class java.util.TreeMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
IntegerTreeMap()
          Constructs a new, empty IntegerMap.
IntegerTreeMap(java.util.Comparator c)
          Constructs a new, empty IntegerMap, sorted according to the given Comparator.
IntegerTreeMap(IntegerMap m)
          Constructs a new map containing the same mappings as the given map.
 
Method Summary
 void add(IntegerMap map)
          Adds another IntegerMap to this map, by adding each entry using add(Object, int).
 void add(java.lang.Object key, int value)
          Adds the specified value to the value already stored for the specified key.
 void addMultiple(IntegerMap map, int factor)
          Adds a multiple of another IntegerMap to this map, which is (almost) equivalent to add(map.multiply(factor)), except that the other map remains unchanged.
 boolean isZero()
          Checks, if every value is zero (or null)
 void multiply(int value)
          Multiplies each value of this map by a common factor
 java.lang.Object put(java.lang.Object key)
          An equivalent to put(key,1)
 java.lang.Object put(java.lang.Object key, int value)
          Associates the specified (int) value with the specified key in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified (Integer) value with the specified key in this map.
 int value(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 
Methods inherited from class java.util.TreeMap
clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, get, headMap, keySet, lastKey, putAll, remove, size, subMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

IntegerTreeMap

public IntegerTreeMap()
Constructs a new, empty IntegerMap.

See Also:
TreeMap.TreeMap()

IntegerTreeMap

public IntegerTreeMap(java.util.Comparator c)
Constructs a new, empty IntegerMap, sorted according to the given Comparator.

Parameters:
c - the comparator that will be used to sort this map
See Also:
TreeMap.TreeMap(Comparator)

IntegerTreeMap

public IntegerTreeMap(IntegerMap m)
Constructs a new map containing the same mappings as the given map.

Parameters:
m - the map that should be copied
See Also:
TreeMap.TreeMap(Map)
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified (Integer) value with the specified key in this map. The value has to be an instance of Integer. This method is equivalent to put(key,value.intValue()).

Specified by:
put in interface java.util.Map
Parameters:
key - the key with which the specified value is to be associated
value - the integer value
Returns:
previous value associated with specified key, or null if there was no mapping for key.
See Also:
Map.put(java.lang.Object, java.lang.Object)

put

public java.lang.Object put(java.lang.Object key,
                            int value)
Description copied from interface: IntegerMap
Associates the specified (int) value with the specified key in this map.

Specified by:
put in interface IntegerMap
Parameters:
key - the key with which the specified value is to be associated
value - the integer value
Returns:
previous value associated with specified key, or null if there was no mapping for key.

put

public java.lang.Object put(java.lang.Object key)
Description copied from interface: IntegerMap
An equivalent to put(key,1)

Specified by:
put in interface IntegerMap
Parameters:
key - the key to be entered into the map (with value 1)
Returns:
previous value associated with specified key, or null if there was no mapping for key.

multiply

public void multiply(int value)
Description copied from interface: IntegerMap
Multiplies each value of this map by a common factor

Specified by:
multiply in interface IntegerMap
Parameters:
value - the factor, which is to be multiplied to each value

value

public int value(java.lang.Object key)
Description copied from interface: IntegerMap
Returns the value to which this map maps the specified key. Returns zero if the map contains no mapping for this key.

Specified by:
value in interface IntegerMap
Parameters:
key - the key whose value should be returned
Returns:
the stored value of the key
See Also:
Map.get(Object)

add

public void add(java.lang.Object key,
                int value)
Description copied from interface: IntegerMap
Adds the specified value to the value already stored for the specified key. If the key is not yet contained in the map, this is the same as put(key, value)

Specified by:
add in interface IntegerMap
Parameters:
key - the key whose value should be changed
value - the increment of the value

add

public void add(IntegerMap map)
Description copied from interface: IntegerMap
Adds another IntegerMap to this map, by adding each entry using add(Object, int).

Specified by:
add in interface IntegerMap
Parameters:
map - the IntegerMap to be added

addMultiple

public void addMultiple(IntegerMap map,
                        int factor)
Description copied from interface: IntegerMap
Adds a multiple of another IntegerMap to this map, which is (almost) equivalent to add(map.multiply(factor)), except that the other map remains unchanged.

Specified by:
addMultiple in interface IntegerMap
Parameters:
map - the map to be added
factor - the factor which is multiplied to the map, before adding it.

isZero

public boolean isZero()
Description copied from interface: IntegerMap
Checks, if every value is zero (or null)

Specified by:
isZero in interface IntegerMap
Returns:
false iff the map contains a non-zero value