Class AbstractReferenceMap.ReferenceEntry
- java.lang.Object
-
- org.apache.commons.collections.map.AbstractHashedMap.HashEntry
-
- org.apache.commons.collections.map.AbstractReferenceMap.ReferenceEntry
-
- All Implemented Interfaces:
java.util.Map.Entry
,KeyValue
- Enclosing class:
- AbstractReferenceMap
protected static class AbstractReferenceMap.ReferenceEntry extends AbstractHashedMap.HashEntry
A MapEntry implementation for the map.If getKey() or getValue() returns null, it means the mapping is stale and should be removed.
- Since:
- Commons Collections 3.1
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractReferenceMap
parent
The parent map-
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap.HashEntry
hashCode, key, next, value
-
-
Constructor Summary
Constructors Constructor Description ReferenceEntry(AbstractReferenceMap parent, AbstractHashedMap.HashEntry next, int hashCode, java.lang.Object key, java.lang.Object 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.java.lang.Object
getKey()
Gets the key from the entry.java.lang.Object
getValue()
Gets the value from the entry.int
hashCode()
Gets the hashcode of the entry using temporary hard references.protected AbstractReferenceMap.ReferenceEntry
next()
Gets the next entry in the bucket.(package private) boolean
purge(java.lang.ref.Reference ref)
Purges the specified referencejava.lang.Object
setValue(java.lang.Object obj)
Sets the value of the entry.protected java.lang.Object
toReference(int type, java.lang.Object referent, int hash)
Constructs a reference of the given type to the given referent.-
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap.HashEntry
toString
-
-
-
-
Field Detail
-
parent
protected final AbstractReferenceMap parent
The parent map
-
-
Constructor Detail
-
ReferenceEntry
public ReferenceEntry(AbstractReferenceMap parent, AbstractHashedMap.HashEntry next, int hashCode, java.lang.Object key, java.lang.Object 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 java.lang.Object getKey()
Gets the key from the entry. This method dereferences weak and soft keys and thus may return null.- Specified by:
getKey
in interfaceKeyValue
- Specified by:
getKey
in interfacejava.util.Map.Entry
- Overrides:
getKey
in classAbstractHashedMap.HashEntry
- Returns:
- the key, which may be null if it was garbage collected
-
getValue
public java.lang.Object getValue()
Gets the value from the entry. This method dereferences weak and soft value and thus may return null.- Specified by:
getValue
in interfaceKeyValue
- Specified by:
getValue
in interfacejava.util.Map.Entry
- Overrides:
getValue
in classAbstractHashedMap.HashEntry
- Returns:
- the value, which may be null if it was garbage collected
-
setValue
public java.lang.Object setValue(java.lang.Object obj)
Sets the value of the entry.- Specified by:
setValue
in interfacejava.util.Map.Entry
- Overrides:
setValue
in classAbstractHashedMap.HashEntry
- Parameters:
obj
- the object to store- Returns:
- the previous value
-
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.- Specified by:
equals
in interfacejava.util.Map.Entry
- Overrides:
equals
in classAbstractHashedMap.HashEntry
- Parameters:
obj
- the other map entry to compare to- Returns:
- true if equal, false if not
-
hashCode
public int hashCode()
Gets the hashcode of the entry using temporary hard references.This implementation uses
hashEntry
on the main map.- Specified by:
hashCode
in interfacejava.util.Map.Entry
- Overrides:
hashCode
in classAbstractHashedMap.HashEntry
- Returns:
- the hashcode of the entry
-
toReference
protected java.lang.Object toReference(int type, java.lang.Object referent, int hash)
Constructs a reference of the given type to the given referent. The reference is registered with the queue for later purging.- 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
-
purge
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 next()
Gets the next entry in the bucket.- Returns:
- the next entry in the bucket
-
-