ecologylab.generic
Class ObjectOrHashMap<K,V>

java.lang.Object
  extended by ecologylab.generic.ObjectOrHashMap<K,V>
All Implemented Interfaces:
java.util.Map<K,V>

public class ObjectOrHashMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>

An attempt to make an object for storing other objects. If only one object exists in the collection, then it is stored here, otherwise it's stored in a hashmap where it can be randomly accessed. This is meant primarily for applications where you're likely to have a LOT of single entires, but may occasionally have a very large number (for example, in a hashmap that maps IP address to connection). ObjectOrHashMap stores a single key value pair, until more than one such pair has been specified, then it switches to using a HashMap instead of the pair. To avoid constructing too many HashMaps, it never destroys the internal HashMap once it has been created. It is assumed that ObjectOrHashMap will generally be used in another Collection and when it is removed from that Collection, it will be destroyed.

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
ObjectOrHashMap()
           
ObjectOrHashMap(K key, V value)
           
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 V get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(java.util.Map<? extends K,? extends V> t)
           
 V remove(java.lang.Object key)
           
 int size()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ObjectOrHashMap

public ObjectOrHashMap()

ObjectOrHashMap

public ObjectOrHashMap(K key,
                       V value)
Method Detail

clear

public void clear()
Specified by:
clear in interface java.util.Map<K,V>
See Also:
Map.clear()

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<K,V>
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<K,V>
See Also:
Map.containsValue(java.lang.Object)

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>
See Also:
Map.entrySet()

get

public V get(java.lang.Object key)
Specified by:
get in interface java.util.Map<K,V>
See Also:
Map.get(java.lang.Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,V>
See Also:
Map.isEmpty()

keySet

public java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,V>
See Also:
Map.keySet()

put

public V put(K key,
             V value)
Specified by:
put in interface java.util.Map<K,V>
See Also:
Map.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(java.util.Map<? extends K,? extends V> t)
Specified by:
putAll in interface java.util.Map<K,V>
See Also:
Map.putAll(java.util.Map)

remove

public V remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,V>
See Also:
Map.remove(java.lang.Object)

size

public int size()
Specified by:
size in interface java.util.Map<K,V>
See Also:
Map.size()

values

public java.util.Collection<V> values()
Specified by:
values in interface java.util.Map<K,V>
See Also:
Map.values()