Class WeakReferenceContainer
- java.lang.Object
-
- org.castor.cache.hashbelt.container.WeakReferenceContainer
-
- All Implemented Interfaces:
java.util.Map<java.lang.Object,java.lang.Object>,Container
public final class WeakReferenceContainer extends java.lang.Object implements Container
An implementation of a container that uses weak references for storing values in the map, so that values can be removed from the map by the system when the system is under memory pressure. Keys, however, are kept strong - so contains() may well find an element, but the value may have been lost. Make sure you test for null returns from put.Note that keys are hard references; in a situation where OutOfMemory will occur, the JVM will first wipe out all unreferenced objects whose only link is a weak reference. An out of memory will wipe all values from the maps which are currently unreferenced. The keys remain until the hashbelt containers are garbage collected, an put is called with that key or when the value should be accessed through any operation of the Container interface.
- Since:
- 1.0
- Version:
- $Revision: 8102 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
- Author:
- Gregory Block, Ralf Joachim
-
-
Constructor Summary
Constructors Constructor Description WeakReferenceContainer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>>entrySet()java.lang.Objectget(java.lang.Object key)longgetTimestamp()Returns the timestamp of this container.booleanisEmpty()java.util.Iterator<java.lang.Object>keyIterator()Returns an iterator over the keys contained in this container.java.util.Set<java.lang.Object>keySet()java.lang.Objectput(java.lang.Object key, java.lang.Object value)voidputAll(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)java.lang.Objectremove(java.lang.Object key)intsize()voidupdateTimestamp()Set the timestamp of this container to System.currentTimeMillis().java.util.Iterator<java.lang.Object>valueIterator()Returns an iterator over the values contained in this container.java.util.Collection<java.lang.Object>values()
-
-
-
Method Detail
-
updateTimestamp
public void updateTimestamp()
Set the timestamp of this container to System.currentTimeMillis().- Specified by:
updateTimestampin interfaceContainer
-
getTimestamp
public long getTimestamp()
Returns the timestamp of this container.- Specified by:
getTimestampin interfaceContainer- Returns:
- The timestamp.
-
keyIterator
public java.util.Iterator<java.lang.Object> keyIterator()
Returns an iterator over the keys contained in this container. If the container is modified while an iteration is in progress, the results of the iteration is not affected and vice-versa.- Specified by:
keyIteratorin interfaceContainer- Returns:
- An iterator over the keys currently contained in the container.
-
valueIterator
public java.util.Iterator<java.lang.Object> valueIterator()
Returns an iterator over the values contained in this container. If the container is modified while an iteration is in progress, the results of the iteration is not affected and vice-versa.- Specified by:
valueIteratorin interfaceContainer- Returns:
- An iterator over the values currently contained in the container.
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)- Specified by:
putin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
putAll
public void putAll(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
- Specified by:
putAllin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
keySet
public java.util.Set<java.lang.Object> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
values
public java.util.Collection<java.lang.Object> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.Object,java.lang.Object>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.Object,java.lang.Object>
-
-