Class SoftMapCache
- java.lang.Object
-
- org.apache.xmlgraphics.image.loader.util.SoftMapCache
-
public class SoftMapCache extends java.lang.Object
Provides a simple cache using soft references and storing the values in a Map. The keys into the Map are hard references, the values are referenced through soft references. The collected values are cleaned up through a ReferenceQueue.
-
-
Constructor Summary
Constructors Constructor Description SoftMapCache(boolean synched)
Creates a new soft cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkReferenceQueue()
Checks the reference queue if any references have been cleared and removes them from the cache.void
clear()
Clears the cache.void
doHouseKeeping()
Triggers some house-keeping, i.e.java.lang.Object
get(java.lang.Object key)
Returns the value associated with the given key.private java.lang.Object
getReference(java.lang.Object key, java.lang.ref.Reference ref)
void
put(java.lang.Object key, java.lang.Object value)
Put a new value in the cache overwriting any existing value with the same key.java.lang.Object
remove(java.lang.Object key)
Removed the value associated with the given key.private java.lang.ref.Reference
wrapInReference(java.lang.Object obj, java.lang.Object key)
-
-
-
Method Detail
-
get
public java.lang.Object get(java.lang.Object key)
Returns the value associated with the given key. If the value is not found or the value has been collected, null is returned.- Parameters:
key
- the key- Returns:
- the requested value or null
-
remove
public java.lang.Object remove(java.lang.Object key)
Removed the value associated with the given key. The value that is removed is returned as the methods result. If the value is not found or the value has been collected, null is returned.- Parameters:
key
- the key- Returns:
- the requested value or null
-
getReference
private java.lang.Object getReference(java.lang.Object key, java.lang.ref.Reference ref)
-
put
public void put(java.lang.Object key, java.lang.Object value)
Put a new value in the cache overwriting any existing value with the same key.- Parameters:
key
- The keyvalue
- the value
-
clear
public void clear()
Clears the cache.
-
doHouseKeeping
public void doHouseKeeping()
Triggers some house-keeping, i.e. processes any pending objects in the reference queue.
-
wrapInReference
private java.lang.ref.Reference wrapInReference(java.lang.Object obj, java.lang.Object key)
-
checkReferenceQueue
private void checkReferenceQueue()
Checks the reference queue if any references have been cleared and removes them from the cache.
-
-