Top Description Inners Constructors Methods
com.github.benmanes.caffeine.cache

pack-priv final Class References

extends Object
Class Inheritance
Annotations
@SuppressWarnings:PMD.MissingStaticMethodInNonInstantiatableClass
Static Imports
java.util.Locale.US, .Objects.requireNonNull

Static utility methods and classes pertaining to weak and soft references.
Author
[email protected] (Ben Manes)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
References.InternalReference<E>

A weak or soft reference that includes the entry's key reference.

pack-priv static class
References.LookupKeyEqualsReference<K>

A short-lived adapter used for looking up an entry in the cache where the keys are weakly held.

pack-priv static class
References.LookupKeyReference<K>

A short-lived adapter used for looking up an entry in the cache where the keys are weakly held.

pack-priv static class
References.SoftValueReference<V>

The value in a cache that holds values softly.

pack-priv static class
References.WeakKeyEqualsReference<K>

The key in a cache that holds the key weakly and uses equals equivalence.

pack-priv static class
References.WeakKeyReference<K>

The key in a cache that holds keys weakly.

pack-priv static class
References.WeakValueReference<V>

The value in a cache that holds values weakly.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Referencesback to summary
private References()
com.github.benmanes.caffeine.cache back to summary

pack-priv Interface References.InternalReference<E>

Known Direct Implementers
com.github.benmanes.caffeine.cache.References.LookupKeyReference, com.github.benmanes.caffeine.cache.References.LookupKeyEqualsReference, com.github.benmanes.caffeine.cache.References.WeakKeyReference, com.github.benmanes.caffeine.cache.References.WeakKeyEqualsReference, com.github.benmanes.caffeine.cache.References.WeakValueReference, com.github.benmanes.caffeine.cache.References.SoftValueReference

A weak or soft reference that includes the entry's key reference.

Method Summary

Modifier and TypeMethod and Description
public @Nullable E

Returns:

The object to which this reference refers, or null if this reference object has been cleared
get
()

Returns this reference object's referent.

public Object

Returns:

the key that is associated to the cached entry
getKeyReference
()

Returns the key that is associated to the cache entry holding this reference.

public default boolean

Returns:

true if this object is equivalent by Object#equals as the argument; false otherwise
objectEquals
(Object
the reference object with which to compare
object
)

Returns true if the arguments is a InternalReference that holds an equivalent element as determined by Object#equals.

public default boolean

Returns:

true if this object is the same as the argument; false otherwise
referenceEquals
(@Nullable Object
the reference object with which to compare
object
)

Returns true if the arguments is a InternalReference that holds the same element.

Method Detail

getback to summary
public @Nullable E get()

Returns this reference object's referent. If this reference object has been cleared, either by the program or by the garbage collector, then this method returns null.

Returns:@Nullable E

The object to which this reference refers, or null if this reference object has been cleared

getKeyReferenceback to summary
public Object getKeyReference()

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

objectEqualsback to summary
public default boolean objectEquals(Object object)

Returns true if the arguments is a InternalReference that holds an equivalent element as determined by Object#equals.

Parameters
object:Object

the reference object with which to compare

Returns:boolean

true if this object is equivalent by Object#equals as the argument; false otherwise

referenceEqualsback to summary
public default boolean referenceEquals(@Nullable Object object)

Returns true if the arguments is a InternalReference that holds the same element. A weakly or softly held element is compared using identity equality.

Parameters
object:@Nullable Object

the reference object with which to compare

Returns:boolean

true if this object is the same as the argument; false otherwise

com.github.benmanes.caffeine.cache back to summary

pack-priv final Class References.LookupKeyEqualsReference<K>

extends Object
implements References.InternalReference<K>
Class Inheritance
  • java.lang.Object
  • com.github.benmanes.caffeine.cache.References.LookupKeyEqualsReference
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference

A short-lived adapter used for looking up an entry in the cache where the keys are weakly held. This InternalReference implementation is not suitable for storing in the cache as the key is strongly held.

Field Summary

Modifier and TypeField and Description
private final int
private final K

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public K
get()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.get.

Returns this reference object's referent.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

hashCodeback to summary
private final int hashCode
keyback to summary
private final K key

Constructor Detail

LookupKeyEqualsReferenceback to summary
public LookupKeyEqualsReference(K key)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public K get()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.get.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.get.

Returns this reference object's referent. If this reference object has been cleared, either by the program or by the garbage collector, then this method returns null.

Returns:K

The object to which this reference refers, or null if this reference object has been cleared

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class References.LookupKeyReference<K>

extends Object
implements References.InternalReference<K>
Class Inheritance
  • java.lang.Object
  • com.github.benmanes.caffeine.cache.References.LookupKeyReference
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference

A short-lived adapter used for looking up an entry in the cache where the keys are weakly held. This InternalReference implementation is not suitable for storing in the cache as the key is strongly held.

Field Summary

Modifier and TypeField and Description
private final int
private final K

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public K
get()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.get.

Returns this reference object's referent.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

hashCodeback to summary
private final int hashCode
keyback to summary
private final K key

Constructor Detail

LookupKeyReferenceback to summary
public LookupKeyReference(K key)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public K get()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.get.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.get.

Returns this reference object's referent. If this reference object has been cleared, either by the program or by the garbage collector, then this method returns null.

Returns:K

The object to which this reference refers, or null if this reference object has been cleared

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class References.SoftValueReference<V>

extends SoftReference<V>
implements References.InternalReference<V>
Class Inheritance
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference

The value in a cache that holds values softly. This class retains a reference to the key in the advent that the value is reclaimed so that the entry can be removed from the cache in constant time.

Field Summary

Modifier and TypeField and Description
private Object

Constructor Summary

AccessConstructor and Description
public
SoftValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue<V> queue)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
setKeyReference(Object keyReference)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.ref.SoftReference:
get

Field Detail

keyReferenceback to summary
private Object keyReference

Constructor Detail

SoftValueReferenceback to summary
public SoftValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue<V> queue)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
setKeyReferenceback to summary
public void setKeyReference(Object keyReference)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class References.WeakKeyEqualsReference<K>

extends WeakReference<K>
implements References.InternalReference<K>
Class Inheritance
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference

The key in a cache that holds the key weakly and uses equals equivalence. This class retains the key's hash code in the advent that the key is reclaimed so that the entry can be removed from the cache in constant time.

Field Summary

Modifier and TypeField and Description
private final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

hashCodeback to summary
private final int hashCode

Constructor Detail

WeakKeyEqualsReferenceback to summary
public WeakKeyEqualsReference(K key, @Nullable ReferenceQueue<K> queue)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv Class References.WeakKeyReference<K>

extends WeakReference<K>
implements References.InternalReference<K>
Class Inheritance
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference
Known Direct Subclasses
com.github.benmanes.caffeine.cache.NodeFactory.RetiredWeakKey, com.github.benmanes.caffeine.cache.NodeFactory.DeadWeakKey

The key in a cache that holds keys weakly. This class retains the key's identity hash code in the advent that the key is reclaimed so that the entry can be removed from the cache in constant time.

Field Summary

Modifier and TypeField and Description
private final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

hashCodeback to summary
private final int hashCode

Constructor Detail

WeakKeyReferenceback to summary
public WeakKeyReference(@Nullable K key, @Nullable ReferenceQueue<K> queue)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.github.benmanes.caffeine.cache back to summary

pack-priv final Class References.WeakValueReference<V>

extends WeakReference<V>
implements References.InternalReference<V>
Class Inheritance
All Implemented Interfaces
com.github.benmanes.caffeine.cache.References.InternalReference

The value in a cache that holds values weakly. This class retains a reference to the key in the advent that the value is reclaimed so that the entry can be removed from the cache in constant time.

Field Summary

Modifier and TypeField and Description
private Object

Constructor Summary

AccessConstructor and Description
public
WeakValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue<V> queue)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
setKeyReference(Object keyReference)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

keyReferenceback to summary
private Object keyReference

Constructor Detail

WeakValueReferenceback to summary
public WeakValueReference(Object keyReference, @Nullable V value, @Nullable ReferenceQueue<V> queue)

Method Detail

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
object:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getKeyReferenceback to summary
public Object getKeyReference()

Implements com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Doc from com.github.benmanes.caffeine.cache.References.InternalReference.getKeyReference.

Returns the key that is associated to the cache entry holding this reference. If the cache holds keys strongly, this is that key instance. Otherwise, the cache holds keys weakly and the WeakKeyReference is returned.

Returns:Object

the key that is associated to the cached entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
setKeyReferenceback to summary
public void setKeyReference(Object keyReference)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override