|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpaul.DataStructs.NonIterableMap<K,V>
public class NonIterableMap<K,V>
NonIterableMap
is a very simple association map that
CANNOT be traversed. As such, it avoids the non-determinism
problems of the HashMap
s, without the cost of building
a linked list (as LinkedHashMap
does). The idea of
having such a class occured to me while trying to find which
HashMap
s do not affect the externally-visible
determinism of a piece of code. Clearly, all maps that are used
only as asssociation maps (without ever being iterated upon) can be
made HashMap. One can use a NonIterableMap instead, and get the
type system check the lack of iterations.
Constructor Summary | |
---|---|
NonIterableMap()
Creates a NonIterableMap backed by a private
HashMap with the default initial capacity. |
|
NonIterableMap(int initialCapacity)
Creates a NonIterableMap backed by a private
HashMap of a certain initial capacity. |
Method Summary | |
---|---|
void |
clear()
Removes all associations from this association
map. |
boolean |
containsKey(K key)
Checks whether this association map contains any
association for the key key . |
V |
get(K key)
Returns the value associated with key in
this association map, or null if no
such value exists. |
boolean |
isEmpty()
Checks whether this association map is empty. |
V |
put(K key,
V value)
Associates the key key with the value
value in this association map. |
V |
remove(K key)
Remove any association for the key key . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NonIterableMap()
NonIterableMap
backed by a private
HashMap
with the default initial capacity.
public NonIterableMap(int initialCapacity)
NonIterableMap
backed by a private
HashMap
of a certain initial capacity.
Method Detail |
---|
public V put(K key, V value)
key
with the value
value
in this
association map.
Returns the previous value attached to key
if
any, or null
oterwise.
public V get(K key)
key
in
this
association map, or null
if no
such value exists.
public V remove(K key)
key
. Returns
the value that key
was mapped to, or
null
if no such value exists.
public boolean containsKey(K key)
this
association map contains any
association for the key key
.
public boolean isEmpty()
this
association map is empty.
public void clear()
this
association
map.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |