au.net.zeus.collection
Interface Referrer<T>

Type Parameters:
T - Referent

public interface Referrer<T>

The public API of package private Reference implementations, it defines the equals and hashCode contracts as well as methods identical to Reference.

Author:
Peter Firmstone
See Also:
Reference, Ref

Method Summary
 void clear()
           
 boolean enqueue()
           
 boolean equals(Object o)
           Equals is calculated on IDENTITY or EQUALITY.
 T get()
           
 int hashCode()
           Standard hashCode calculation for IDENTITY based references, where k is the referent.
 boolean isEnqueued()
           
 

Method Detail

get

T get()
See Also:
Reference.get()

clear

void clear()
See Also:
Reference.clear()

isEnqueued

boolean isEnqueued()
Returns:
true if enqueued.
See Also:
Reference.isEnqueued()

enqueue

boolean enqueue()
Returns:
See Also:
Reference.enqueue()

equals

boolean equals(Object o)

Equals is calculated on IDENTITY or EQUALITY.

IDENTITY calculation:

if (this == o) return true;
if (!(o instanceof Referrer)) return false;
Object k1 = get();
Object k2 = ((Referrer) o).get();
if ( k1 != null && k1 == k2 ) return true;
return ( k1 == null && k2 == null && hashCode() == o.hashCode());

EQUALITY calculation:

if (this == o) return true; // Same reference.
if (!(o instanceof Referrer)) return false;
Object k1 = get();
Object k2 = ((Referrer) o).get();
if ( k1 != null && k1.equals(k2)) return true;
return ( k1 == null && k2 == null && hashCode() == o.hashCode());

Overrides:
equals in class Object
Parameters:
o -
Returns:
See Also:
Ref

hashCode

int hashCode()

Standard hashCode calculation for IDENTITY based references, where k is the referent. This may be stored in a final field:


int hash = 7;
hash = 29 * hash + System.identityHashCode(k);
hash = 29 * hash + k.getClass().hashCode();

Standard hashCode calculation for EQUALITY based references, where k is the referent:


int hash = 7;
hash = 29 * hash + k.hashCode();
hash = 29 * hash + k.getClass().hashCode();

The hash must be calculated during construction and if the reference is cleared, the recorded hashCode returned. While the referent remains reachable the hashCode must be calculated each time.

Overrides:
hashCode in class Object
Returns:


Copyright 2010-2012, Zeus Project Services Pty Ltd.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.