All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.cglib.core.WeakCacheKey Maven / Gradle / Ivy

There is a newer version: 6.1.6
Show newest version
package org.springframework.cglib.core;

import java.lang.ref.WeakReference;

/**
 * Allows to check for object equality, yet the class does not keep strong reference to the target.
 * {@link #equals(Object)} returns true if and only if the reference is not yet expired and target
 * objects are equal in terms of {@link #equals(Object)}.
 * 

* This an internal class, thus it might disappear in future cglib releases. * * @param type of the reference */ public class WeakCacheKey extends WeakReference { private final int hash; public WeakCacheKey(T referent) { super(referent); this.hash = referent.hashCode(); } @Override public boolean equals(Object obj) { if (!(obj instanceof WeakCacheKey weakCacheKey)) { return false; } Object ours = get(); Object theirs = weakCacheKey.get(); return ours != null && theirs != null && ours.equals(theirs); } @Override public int hashCode() { return hash; } @Override public String toString() { T t = get(); return t == null ? "Clean WeakIdentityKey, hash: " + hash : t.toString(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy