Example usage for java.lang.ref Reference hashCode

List of usage examples for java.lang.ref Reference hashCode

Introduction

In this page you can find the example usage for java.lang.ref Reference hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:org.apache.ojb.broker.util.ReferenceMap.java

private void purge(Reference ref) {
    // The hashCode of the reference is the hashCode of the
    // mapping key, even if the reference refers to the
    // mapping value...
    int hash = ref.hashCode(); // note: hashCode() is referined
    int index = indexFor(hash);
    Entry previous = null;//from www. ja v  a 2  s.  c  o  m
    Entry entry = table[index];
    while (entry != null) {
        if (entry.purge(ref)) {
            if (previous == null)
                table[index] = entry.next;
            else
                previous.next = entry.next;
            this.size--;
            return;
        }
        previous = entry;
        entry = entry.next;
    }

}

From source file:org.apache.openjpa.lib.util.ReferenceHashMap.java

protected void purge(Reference ref) {
    // the logic for this method is taken from the original purge method
    // we're overriding, with added logic to track the expired key/value
    int index = hashIndex(ref.hashCode(), data.length);
    AccessibleEntry entry = (AccessibleEntry) data[index];
    AccessibleEntry prev = null;/*w w  w .  j a va 2 s. co  m*/
    Object key = null, value = null;
    while (entry != null) {
        if (purge(entry, ref)) {
            if (isHard(keyType))
                key = entry.key();
            else if (isHard(valueType))
                value = entry.value();

            if (prev == null)
                data[index] = entry.nextEntry();
            else
                prev.setNextEntry(entry.nextEntry());
            size--;
            break;
        }
        prev = entry;
        entry = entry.nextEntry();
    }

    if (key != null)
        valueExpired(key);
    else if (value != null)
        keyExpired(value);
}