jpaul.DataStructs
Class NonIterableMap<K,V>

java.lang.Object
  extended by jpaul.DataStructs.NonIterableMap<K,V>
All Implemented Interfaces:
java.io.Serializable

public class NonIterableMap<K,V>
extends java.lang.Object
implements java.io.Serializable

NonIterableMap is a very simple association map that CANNOT be traversed. As such, it avoids the non-determinism problems of the HashMaps, 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 HashMaps 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.

Version:
$Id: NonIterableMap.java,v 1.4 2006/02/15 17:59:16 salcianu Exp $
Author:
Alex Salcianu - salcianu@alum.mit.edu
See Also:
Serialized Form

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

NonIterableMap

public NonIterableMap()
Creates a NonIterableMap backed by a private HashMap with the default initial capacity.


NonIterableMap

public NonIterableMap(int initialCapacity)
Creates a NonIterableMap backed by a private HashMap of a certain initial capacity.

Method Detail

put

public V put(K key,
             V value)
Associates the key key with the value value in this association map. Returns the previous value attached to key if any, or null oterwise.


get

public V get(K key)
Returns the value associated with key in this association map, or null if no such value exists.


remove

public V remove(K key)
Remove any association for the key key. Returns the value that key was mapped to, or null if no such value exists.


containsKey

public boolean containsKey(K key)
Checks whether this association map contains any association for the key key.


isEmpty

public boolean isEmpty()
Checks whether this association map is empty.


clear

public void clear()
Removes all associations from this association map.



Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu