edu.umd.cloud9.util.map
Interface MapKI<K>

Type Parameters:
K - type of the keys
All Known Implementing Classes:
HMapKI, HMapKIW, HMapSIW

public interface MapKI<K>

Map from arbitrary objects to ints.


Nested Class Summary
static interface MapKI.Entry<K>
          A map entry (key-value pair) for MapKI.
 
Field Summary
static int DEFAULT_VALUE
           
 
Method Summary
 void clear()
          Removes all of the mappings from this map.
 boolean containsKey(K key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(int value)
          Returns true if this map contains one or more mappings with the specified value.
 Set<MapKI.Entry<K>> entrySet()
          Returns a Set view of the mappings contained in this map.
 boolean equals(Object o)
          Compares the specified object with this map for equality.
 int get(K key)
          Returns the value to which the specified key is mapped, or throws NoSuchElementException if this map contains no mapping for the key.
 int hashCode()
          Returns the hash code value for this map.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 Set<K> keySet()
          Returns a Set view of the keys contained in this map.
 int put(K key, int value)
          Associates the specified value with the specified key in this map.
 void putAll(MapKI<? extends K> m)
          Copies all of the mappings from the specified map to this map.
 int remove(K key)
          Removes the mapping for a key from this map if it is present.
 int size()
          Returns the number of key-value mappings in this map.
 Collection<Integer> values()
          Returns a Collection view of the values contained in this map.
 

Field Detail

DEFAULT_VALUE

static final int DEFAULT_VALUE
See Also:
Constant Field Values
Method Detail

size

int size()
Returns the number of key-value mappings in this map.

Returns:
the number of key-value mappings in this map

isEmpty

boolean isEmpty()
Returns true if this map contains no key-value mappings.

Returns:
true if this map contains no key-value mappings

containsKey

boolean containsKey(K key)
Returns true if this map contains a mapping for the specified key.

Parameters:
key - key whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key

containsValue

boolean containsValue(int value)
Returns true if this map contains one or more mappings with the specified value.

Parameters:
value - value whose presence in this map is to be tested
Returns:
true this map contains one or more mappings with the specified value

get

int get(K key)
Returns the value to which the specified key is mapped, or throws NoSuchElementException if this map contains no mapping for the key.

Parameters:
key - the key whose associated value is to be returned
Returns:
the value to which the specified key is mapped
Throws:
NoSuchElementException - if the key is not contained in this map

put

int put(K key,
        int value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value.

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key

remove

int remove(K key)
Removes the mapping for a key from this map if it is present. No action is performed if this map does not contain the key.

Parameters:
key - key whose mapping is to be removed from the map

putAll

void putAll(MapKI<? extends K> m)
Copies all of the mappings from the specified map to this map.

Parameters:
m - mappings to be stored in this map

clear

void clear()
Removes all of the mappings from this map. The map will be empty after this call returns.


keySet

Set<K> keySet()
Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. See Map.keySet() for more details.

Returns:
a set view of the keys contained in this map

values

Collection<Integer> values()
Returns a Collection view of the values contained in this map. Note that this is a inefficient operation since it triggers autoboxing of the int values, which is exactly what this implementation is trying to avoid. Unlike a standard Java Map, values in the backing map cannot be altered with this collection view.

Returns:
a collection view of the values contained in this map

entrySet

Set<MapKI.Entry<K>> entrySet()
Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. See Map.entrySet() for more details.

Returns:
a set view of the mappings contained in this map

equals

boolean equals(Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the MapKI interface.

Overrides:
equals in class Object
Parameters:
o - object to be compared for equality with this map
Returns:
true if the specified object is equal to this map

hashCode

int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object.hashCode().

Overrides:
hashCode in class Object
Returns:
the hash code value for this map
See Also:
MapKI.Entry.hashCode(), Object.equals(Object), equals(Object)