org.cojen.util
Class ReferencedValueHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.cojen.util.ReferencedValueHashMap<K,V>
All Implemented Interfaces:
Cloneable, Map<K,V>
Direct Known Subclasses:
SoftValuedHashMap, WeakValuedHashMap

public abstract class ReferencedValueHashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Cloneable

A Map that references its values and can be used as a simple cache. Instances are not thread-safe and must be wrapped with Collections.synchronizedMap to be made thread-safe.

Note: Referenced entries may be automatically removed during either accessor or mutator operations, possibly causing a concurrent modification to be detected. Therefore, even if multiple threads are only accessing this map, be sure to synchronize this map first. Also, do not rely on the value returned by size() when using an iterator from this map. The iterators may return less entries than the amount reported by size().

Author:
Brian S O'Neill

Constructor Summary
ReferencedValueHashMap()
          Constructs a new, empty map with a default capacity and load factor, which is 0.75.
ReferencedValueHashMap(int initialCapacity)
          Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.
ReferencedValueHashMap(int initialCapacity, float loadFactor)
          Constructs a new, empty map with the specified initial capacity and the specified load factor.
ReferencedValueHashMap(Map<? extends K,? extends V> t)
          Constructs a new map with the same mappings as the given map.
 
Method Summary
 void clear()
           
 Object clone()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> t)
           
 V remove(Object key)
           
 int size()
           
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ReferencedValueHashMap

public ReferencedValueHashMap(int initialCapacity,
                              float loadFactor)
Constructs a new, empty map with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the HashMap.
loadFactor - the load factor of the HashMap
Throws:
IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

ReferencedValueHashMap

public ReferencedValueHashMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.

Parameters:
initialCapacity - the initial capacity of the HashMap.
Throws:
IllegalArgumentException - if the initial capacity is less than zero.

ReferencedValueHashMap

public ReferencedValueHashMap()
Constructs a new, empty map with a default capacity and load factor, which is 0.75.


ReferencedValueHashMap

public ReferencedValueHashMap(Map<? extends K,? extends V> t)
Constructs a new map with the same mappings as the given map. The map is created with a capacity of twice the number of mappings in the given map or 11 (whichever is greater), and a default load factor, which is 0.75.

Method Detail

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class AbstractMap<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class AbstractMap<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMap<K,V>

putAll

public void putAll(Map<? extends K,? extends V> t)
Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class AbstractMap<K,V>

clear

public void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMap<K,V>

clone

public Object clone()
Overrides:
clone in class AbstractMap<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class AbstractMap<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class AbstractMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

toString

public String toString()
Overrides:
toString in class AbstractMap<K,V>


Copyright © 2004-2008 Brian S O'Neill. All Rights Reserved.