org.semanticweb.elk.util.collections.entryset
Class WeakKeyEntry<K,T>

java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.WeakReference<K>
          extended by org.semanticweb.elk.util.collections.entryset.WeakKeyEntry<K,T>
Type Parameters:
K - the type of the keys of the record
T - the type of the next element the record is connected with
All Implemented Interfaces:
KeyEntry<T,K>

public abstract class WeakKeyEntry<K,T>
extends WeakReference<K>
implements KeyEntry<T,K>

A prototype class for entries with weak keys, which can be collected by the garbage collector. Sub-classes should implement the method for computing the equality function for the entry and hash code of the keys, which will be used for initializing the hash code of the entry. The hashCode and equals methods should be compatible as usual. Note that the keys are mutable because they may become null at some later time. Thus, special care needs to be taken when implementing and using the equals method: it might be the case that the result of equality changes over time. For example, it would be unsafe to define two entries equal if both of them have null keys, since they might have been initialized with different hash values, and equals would be not compatible with the hash code. The hash code function does not have such a side effect

Author:
"Yevgeny Kazakov"

Field Summary
protected  int hash
          The value used as a hash code of this record
protected  KeyEntry<T,? extends T> next
          The reference to the next element
 
Constructor Summary
WeakKeyEntry(K key)
          Create a weak record for the key
 
Method Summary
abstract  int computeHashCode()
          Compute the value which will be used as a final hash code for this object.
abstract  boolean equals(Object object)
           
 K getKey()
           
 KeyEntry<T,? extends T> getNext()
          Returns the next next element of the entry, or null if there is no next element
 int hashCode()
           
 void setNext(KeyEntry<T,? extends T> next)
          Setting the input element as the next element of the entry.
 
Methods inherited from class java.lang.ref.Reference
clear, enqueue, get, isEnqueued
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hash

protected final int hash
The value used as a hash code of this record


next

protected KeyEntry<T,? extends T> next
The reference to the next element

Constructor Detail

WeakKeyEntry

public WeakKeyEntry(K key)
Create a weak record for the key

Parameters:
key - the key for which the weak record is created
Method Detail

getKey

public K getKey()
Specified by:
getKey in interface KeyEntry<T,K>

setNext

public void setNext(KeyEntry<T,? extends T> next)
Setting the input element as the next element of the entry.

Parameters:
next - the object that should be set as the next element of the record

getNext

public KeyEntry<T,? extends T> getNext()
Returns the next next element of the entry, or null if there is no next element

Returns:
the next element of the entry

hashCode

public int hashCode()
Overrides:
hashCode in class Object

computeHashCode

public abstract int computeHashCode()
Compute the value which will be used as a final hash code for this object. Must be compatible with the equals(Object) method usual.

Returns:
the value to be used as a hash code for this object

equals

public abstract boolean equals(Object object)
Overrides:
equals in class Object


Copyright © 2011-2013 Department of Computer Science, University of Oxford. All Rights Reserved.