org.geotools.util
Class WeakValueHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.geotools.util.WeakValueHashMap<K,V>
Type Parameters:
K - The class of key elements.
V - The class of value elements.
All Implemented Interfaces:
java.util.Map<K,V>

public class WeakValueHashMap<K,V>
extends java.util.AbstractMap<K,V>

A hashtable-based Map implementation with weak values. An entry in a WeakValueHashMap will automatically be removed when its value is no longer in ordinary use. This class is similar to the standard WeakHashMap class provided in J2SE, except that weak references are hold on values instead of keys.

The WeakValueHashMap class is thread-safe.

Since:
2.0
Version:
$Id: WeakValueHashMap.java 31445 2008-09-07 18:14:23Z desruisseaux $
Author:
Martin Desruisseaux (IRD)
See Also:
WeakHashMap, WeakHashSet

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
WeakValueHashMap()
          Creates a WeakValueHashMap.
WeakValueHashMap(int initialSize)
          Creates a WeakValueHashMap of the requested size and default load factor.
WeakValueHashMap(java.util.Map<K,V> map)
          Creates a new WeakValueHashMap populated with the contents of the provied map.
 
Method Summary
 void clear()
          Removes all of the elements from this map.
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more keys to this value.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Returns a set view of the mappings contained in this map.
 V get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 V put(K key, V value)
          Associates the specified value with the specified key in this map.
 V remove(java.lang.Object key)
          Removes the mapping for this key from this map if present.
 int size()
          Returns the number of key-value mappings in this map.
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, isEmpty, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WeakValueHashMap

public WeakValueHashMap()
Creates a WeakValueHashMap.


WeakValueHashMap

public WeakValueHashMap(int initialSize)
Creates a WeakValueHashMap of the requested size and default load factor.

Parameters:
initialSize - The initial size.

WeakValueHashMap

public WeakValueHashMap(java.util.Map<K,V> map)
Creates a new WeakValueHashMap populated with the contents of the provied map.

Parameters:
map - Initial contents of the WeakValueHashMap.
Method Detail

size

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

Specified by:
size in interface java.util.Map<K,V>
Overrides:
size in class java.util.AbstractMap<K,V>

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to this value.

Specified by:
containsValue in interface java.util.Map<K,V>
Overrides:
containsValue in class java.util.AbstractMap<K,V>
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to this value.

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.
Throws:
java.lang.NullPointerException - If key is null.

get

public V get(java.lang.Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>
Parameters:
key - Key whose associated value is to be returned.
Returns:
The value to which this map maps the specified key.
Throws:
java.lang.NullPointerException - if the key is null.

put

public V put(K key,
             V value)
Associates the specified value with the specified key in this map. The value is associated using a WeakReference.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key.
Throws:
java.lang.NullPointerException - if the key or the value is null.

remove

public V remove(java.lang.Object key)
Removes the mapping for this key from this map if present.

Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.AbstractMap<K,V>
Parameters:
key - key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no entry for key.

clear

public void clear()
Removes all of the elements from this map.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.AbstractMap<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns a set view of the mappings contained in this map. Each element in this set is a Map.Entry. The current implementation thrown UnsupportedOperationException.

Specified by:
entrySet in interface java.util.Map<K,V>
Specified by:
entrySet in class java.util.AbstractMap<K,V>
Returns:
a set view of the mappings contained in this map.


Copyright © 1996-2010 Geotools. All Rights Reserved.