org.apache.commons.collections.map

Class AbstractReferenceMap.ReferenceEntry

protected static class AbstractReferenceMap.ReferenceEntry extends 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
protected AbstractReferenceMapparent
The parent map
Constructor Summary
ReferenceEntry(AbstractReferenceMap parent, HashEntry next, int hashCode, Object key, Object value)
Creates a new entry object for the ReferenceMap.
Method Summary
booleanequals(Object obj)
Compares this map entry to another.
ObjectgetKey()
Gets the key from the entry.
ObjectgetValue()
Gets the value from the entry.
inthashCode()
Gets the hashcode of the entry using temporary hard references.
protected AbstractReferenceMap.ReferenceEntrynext()
Gets the next entry in the bucket.
ObjectsetValue(Object obj)
Sets the value of the entry.
protected ObjecttoReference(int type, Object referent, int hash)
Constructs a reference of the given type to the given referent.

Field Detail

parent

protected final AbstractReferenceMap parent
The parent map

Constructor Detail

ReferenceEntry

public ReferenceEntry(AbstractReferenceMap parent, HashEntry next, int hashCode, Object key, Object value)
Creates a new entry object for the ReferenceMap.

Parameters: parent the parent map next the next entry in the hash bucket hashCode the hash code of the key key the key value the value

Method Detail

equals

public boolean equals(Object obj)
Compares this map entry to another.

This implementation uses isEqualKey and isEqualValue on the main map for comparison.

Parameters: obj the other map entry to compare to

Returns: true if equal, false if not

getKey

public Object getKey()
Gets the key from the entry. This method dereferences weak and soft keys and thus may return null.

Returns: the key, which may be null if it was garbage collected

getValue

public Object getValue()
Gets the value from the entry. This method dereferences weak and soft value and thus may return null.

Returns: the value, which may be null if it was garbage collected

hashCode

public int hashCode()
Gets the hashcode of the entry using temporary hard references.

This implementation uses hashEntry on the main map.

Returns: the hashcode of the entry

next

protected AbstractReferenceMap.ReferenceEntry next()
Gets the next entry in the bucket.

Returns: the next entry in the bucket

setValue

public Object setValue(Object obj)
Sets the value of the entry.

Parameters: obj the object to store

Returns: the previous value

toReference

protected Object toReference(int type, 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 WEAK referent the object to refer to hash 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

Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.