org.jomc.util
Class WeakIdentityHashMap.Entry

Package class diagram package WeakIdentityHashMap.Entry
java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.WeakReference
          extended by org.jomc.util.WeakIdentityHashMap.Entry
All Implemented Interfaces:
Map.Entry
Enclosing class:
WeakIdentityHashMap

private static class WeakIdentityHashMap.Entry
extends WeakReference
implements Map.Entry

A map entry (key-value pair) with weakly referenced key.

The WeakIdentityHashMap.entrySet method returns a collection-view of the map, whose elements are of this class. The only way to obtain a reference to a map entry is from the iterator of this collection-view. These Map.Entry objects are valid only for the duration of the iteration; more formally, the behavior of a map entry is undefined if the backing map has been modified after the entry was returned by the iterator, except through the setValue operation on the map entry.

See Also:
WeakIdentityHashMap.entrySet()

Field Summary
private  int hashCode
          The hash code value of the key.
private  WeakIdentityHashMap.Entry next
          The next entry in the bucket.
private  boolean removed
          Flag indicating that this entry got removed from the map.
private  Object value
          The value of the entry.
 
Constructor Summary
WeakIdentityHashMap.Entry(Object key, Object value, int hashCode, ReferenceQueue queue)
           
 
Method Summary
 boolean equals(Object o)
          Compares a given object with this entry for equality.
 Object getKey()
          Gets the key corresponding to this entry.
 Object getValue()
          Gets the value corresponding to this entry.
 int hashCode()
          Gets the hash code value for this map entry.
private  String internalString()
          Creates a string representing the properties of the instance.
 Object setValue(Object value)
          Replaces the value corresponding to this entry with the specified value.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.ref.Reference
clear, enqueue, get, isEnqueued
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

private Object value
The value of the entry.


next

private WeakIdentityHashMap.Entry next
The next entry in the bucket.


removed

private boolean removed
Flag indicating that this entry got removed from the map.


hashCode

private final int hashCode
The hash code value of the key.

Constructor Detail

WeakIdentityHashMap.Entry

WeakIdentityHashMap.Entry(Object key,
                          Object value,
                          int hashCode,
                          ReferenceQueue queue)
Method Detail

getKey

public Object getKey()
Gets the key corresponding to this entry.

Specified by:
getKey in interface Map.Entry
Returns:
The key corresponding to this entry.
Throws:
IllegalStateException - if the entry got removed from the backing map (either due to an iterator's remove operation or due to the key having been garbage collected).

getValue

public Object getValue()
Gets the value corresponding to this entry.

Specified by:
getValue in interface Map.Entry
Returns:
the value corresponding to this entry.
Throws:
IllegalStateException - if the entry got removed from the backing map (either due to an iterator's remove operation or due to the key having been garbage collected).

setValue

public Object setValue(Object value)
Replaces the value corresponding to this entry with the specified value.

Specified by:
setValue in interface Map.Entry
Parameters:
value - The new value to be stored in this entry.
Returns:
old value corresponding to the entry.
Throws:
NullPointerException - if value is null.
IllegalStateException - if the entry got removed from the backing map (either due to an iterator's remove operation or due to the key having been garbage collected).

toString

public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
Returns:
a string representation of the object.

equals

public boolean equals(Object o)
Compares a given object with this entry for equality.

Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

( e1.getKey() == e2.getKey() ) && ( e1.getValue().equals( e2.getValue() ) )

Specified by:
equals in interface Map.Entry
Overrides:
equals in class Object
Parameters:
o - The object to be compared for equality with this map entry.
Returns:
true if o is equal to this map entry; false if o is not equal to this map entry.

hashCode

public int hashCode()
Gets the hash code value for this map entry.

The hash code of a map entry e is defined to be:

( e.getKey() == null ? 0 : e.getKey().hashCode() ) ^ ( e.getValue() == null ? 0 : e.getValue().hashCode() )

Specified by:
hashCode in interface Map.Entry
Overrides:
hashCode in class Object
Returns:
the hash code value for this map entry.

internalString

private String internalString()
Creates a string representing the properties of the instance.

Returns:
a string representing the properties of the instance.


Copyright © 2005-2009 The JOMC Project. All Rights Reserved.