Package org.intermine.util
Class ReferenceMap<K,V>
- java.lang.Object
-
- org.intermine.util.ReferenceMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
java.util.Map<K,V>
- Direct Known Subclasses:
SoftReferenceMap
,WeakReferenceMap
public abstract class ReferenceMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
This is a Map implementation designed specifically for people intending to create a cache. The class should be subclassed to provide soft or weak reference behaviour. The keys are held strongly, but the values are held weakly or softly, so the values can be garbage-collected. When an entry is garbage-collected, its key is removed from the Map on the next Map activity.The entrySet() and values() methods of this class do not work.
- Author:
- Matthew Wakeling
- See Also:
SoftReference
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
ReferenceMap.ReferenceWithKey<K>
Interface for entries in the map.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
name
protected static org.intermine.util.ReferenceMap.NullValue
NULL_VALUE
protected java.lang.ref.ReferenceQueue<java.lang.Object>
queue
protected java.util.Map<K,java.lang.ref.Reference<java.lang.Object>>
subMap
-
Constructor Summary
Constructors Constructor Description ReferenceMap()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
boolean
equals(java.lang.Object o)
V
get(java.lang.Object key)
int
hashCode()
boolean
isEmpty()
java.util.Set<K>
keySet()
protected abstract java.lang.ref.Reference<java.lang.Object>
newRef(java.lang.Object value, java.lang.ref.ReferenceQueue<java.lang.Object> queue, K key)
Private method to create a new ReferenceWithKey object.V
put(K key, V value)
void
putAll(java.util.Map<? extends K,? extends V> t)
V
remove(java.lang.Object key)
int
size()
java.lang.String
toString()
java.util.Collection<V>
values()
-
-
-
Field Detail
-
NULL_VALUE
protected static final org.intermine.util.ReferenceMap.NullValue NULL_VALUE
-
subMap
protected java.util.Map<K,java.lang.ref.Reference<java.lang.Object>> subMap
-
queue
protected java.lang.ref.ReferenceQueue<java.lang.Object> queue
-
name
protected java.lang.String name
-
-
Method Detail
-
containsKey
public boolean containsKey(java.lang.Object key)
-
newRef
protected abstract java.lang.ref.Reference<java.lang.Object> newRef(java.lang.Object value, java.lang.ref.ReferenceQueue<java.lang.Object> queue, K key)
Private method to create a new ReferenceWithKey object. This should be overridden by subclasses wishing to create soft/weak behaviour.- Parameters:
value
- the value put into the Referencequeue
- the ReferenceQueue to register the Reference inkey
- the key- Returns:
- a ReferenceWithKey, that is also a Reference (long story, no multiple inheritance in Java, and Reference is daftly an abstract class rather than an interface)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
values
public java.util.Collection<V> values()
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-