complex
Interface IntegerMap

All Superinterfaces:
java.util.Map
All Known Implementing Classes:
IntegerTreeMap

public interface IntegerMap
extends java.util.Map

A representation of a Map with value-type Integer, supporting a variety of additional operations.

The sum of two IntegerMaps is defined as a map on the union of the keys. If a key is contained in both maps, it is mapped to the sum of the two original values, otherwise to its unique original value.

The multiplication of an IntegerMap with an integer i is defined to be the multiplication of each value with i.

Author:
karsten

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
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.
 int value(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            int value)
Associates the specified (int) value with the specified key in this 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.

put

public java.lang.Object put(java.lang.Object key)
An equivalent to put(key,1)

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)
Multiplies each value of this map by a common factor

Parameters:
value - the factor, which is to be multiplied to each value

add

public void add(java.lang.Object key,
                int value)
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)

Parameters:
key - the key whose value should be changed
value - the increment of the value

add

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

Parameters:
map - the IntegerMap to be added

value

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

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

addMultiple

public 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.

Parameters:
map - the map to be added
factor - the factor which is multiplied to the map, before adding it.

isZero

public boolean isZero()
Checks, if every value is zero (or null)

Returns:
false iff the map contains a non-zero value