no.sesat.commons.ref
Class ReferenceMap<K,V>

java.lang.Object
  extended by no.sesat.commons.ref.ReferenceMap<K,V>
Type Parameters:
K - key type
V - value type

public final class ReferenceMap<K,V>
extends Object

Provides a Map where values are referenced either weakly or softly. This can be used to cache immutable objects without preventing them from bing garbaged collected.

Concurrency and synchronisation of this class fallbacks to the Map implementation passed in as the cache parameter in the constructor. For example: use a Hashtable for synchronised access, a ConcurrentHashMap for concurrent access, and a HashMap for single threaded access (make sure to specify the argument indicating single thread use).

This implementation improves over org.apache.commons.collections.map.ReferenceMap in that the synchronisation and concurrency is determined through delegation to the map supplied in the constructor as described above.

Version:
$Id: ReferenceMap.java 1127 2009-01-21 16:16:08Z ssmiweve $

Nested Class Summary
static class ReferenceMap.Type
           
 
Constructor Summary
ReferenceMap(ReferenceMap.Type type, Map<K,Reference<V>> cache)
           
ReferenceMap(ReferenceMap.Type type, Map<K,Reference<V>> cache, boolean singleThreaded)
           
 
Method Summary
 V get(K key)
           
 V put(K key, V value)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReferenceMap

public ReferenceMap(ReferenceMap.Type type,
                    Map<K,Reference<V>> cache)
Parameters:
type -
cache -

ReferenceMap

public ReferenceMap(ReferenceMap.Type type,
                    Map<K,Reference<V>> cache,
                    boolean singleThreaded)
Parameters:
type -
cache -
singleThreaded -
Method Detail

put

public V put(K key,
             V value)
Parameters:
key -
value -
Returns:

get

public V get(K key)
Parameters:
key -
Returns:

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 Schibsted Søk AS. All Rights Reserved.