Class AbstractReferenceMap.ReferenceEntry<K,V>
- java.lang.Object
-
- org.apache.openjpa.lib.util.collections.AbstractHashedMap.HashEntry<K,V>
-
- org.apache.openjpa.lib.util.collections.AbstractReferenceMap.ReferenceEntry<K,V>
-
- All Implemented Interfaces:
java.util.Map.Entry<K,V>
,KeyValue<K,V>
- Enclosing class:
- AbstractReferenceMap<K,V>
protected static class AbstractReferenceMap.ReferenceEntry<K,V> extends AbstractHashedMap.HashEntry<K,V>
A MapEntry implementation for the map.If getKey() or getValue() returns null, it means the mapping is stale and should be removed.
- Since:
- 3.1
-
-
Field Summary
-
Fields inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap.HashEntry
hashCode, key, next, value
-
-
Constructor Summary
Constructors Constructor Description ReferenceEntry(AbstractReferenceMap<K,V> parent, AbstractHashedMap.HashEntry<K,V> next, int hashCode, K key, V value)
Creates a new entry object for the ReferenceMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Compares this map entry to another.K
getKey()
Gets the key from the entry.V
getValue()
Gets the value from the entry.int
hashCode()
Gets the hashcode of the entry using temporary hard references.protected AbstractReferenceMap.ReferenceEntry<K,V>
next()
Gets the next entry in the bucket.protected void
nullValue()
This method can be overriden to provide custom logic to purge valueprotected void
onPurge()
This is the callback for custom "after purge" logicprotected boolean
purge(java.lang.ref.Reference<?> ref)
Purges the specified referenceV
setValue(V obj)
Sets the value of the entry.protected <T> java.lang.Object
toReference(AbstractReferenceMap.ReferenceStrength type, T referent, int hash)
Constructs a reference of the given type to the given referent.-
Methods inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap.HashEntry
toString
-
-
-
-
Constructor Detail
-
ReferenceEntry
public ReferenceEntry(AbstractReferenceMap<K,V> parent, AbstractHashedMap.HashEntry<K,V> next, int hashCode, K key, V value)
Creates a new entry object for the ReferenceMap.- Parameters:
parent
- the parent mapnext
- the next entry in the hash buckethashCode
- the hash code of the keykey
- the keyvalue
- the value
-
-
Method Detail
-
getKey
public K getKey()
Gets the key from the entry. This method dereferences weak and soft keys and thus may return null.
-
getValue
public V getValue()
Gets the value from the entry. This method dereferences weak and soft value and thus may return null.
-
equals
public boolean equals(java.lang.Object obj)
Compares this map entry to another.This implementation uses
isEqualKey
andisEqualValue
on the main map for comparison.
-
hashCode
public int hashCode()
Gets the hashcode of the entry using temporary hard references.This implementation uses
hashEntry
on the main map.
-
toReference
protected <T> java.lang.Object toReference(AbstractReferenceMap.ReferenceStrength type, T referent, int hash)
Constructs a reference of the given type to the given referent. The reference is registered with the queue for later purging.- Type Parameters:
T
- the type of the referenced object- Parameters:
type
- HARD, SOFT or WEAKreferent
- the object to refer tohash
- the hash code of the key of the mapping; this number might be different from referent.hashCode() if the referent represents a value and not a key- Returns:
- the reference to the object
-
onPurge
protected void onPurge()
This is the callback for custom "after purge" logic
-
purge
protected boolean purge(java.lang.ref.Reference<?> ref)
Purges the specified reference- Parameters:
ref
- the reference to purge- Returns:
- true or false
-
next
protected AbstractReferenceMap.ReferenceEntry<K,V> next()
Gets the next entry in the bucket.- Returns:
- the next entry in the bucket
-
nullValue
protected void nullValue()
This method can be overriden to provide custom logic to purge value
-
-