Package org.apache.sis.util.collection
Class WeakEntry<E>
java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.WeakReference<E>
org.apache.sis.util.collection.WeakEntry<E>
- Type Parameters:
E
- the type of elements in the collection.
- All Implemented Interfaces:
Disposable
- Direct Known Subclasses:
WeakHashSet.Entry
,WeakValueHashMap.Entry
A weak reference to an element in a
WeakHashSet
or WeakValueHashMap
.
This is an element in a linked list. When the reference is disposed, it is removed
from the enclosing collection.- Since:
- 0.3
- Version:
- 0.3
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final int
The absolute value of the hash value of the referenced object.(package private) static final int
The mask to apply on hash code values for ensuring positive values.private static final Logger
The logger where to logs collection events, if logging at the finest level is enabled.(package private) static final int
Minimal capacity for the internal table of entries.The next entry, ornull
if there is none.(package private) static final long
Number of nanoseconds to wait before to rehash the table for reducing its size. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <E> int
Counts the number of entries in the given table.(package private) static int
lowerCapacityThreshold
(int capacity) If the number of elements is lower than this threshold, then the table should be rehashed for saving space.(package private) static <E> WeakEntry<E>[]
Rehashes the given table.(package private) final boolean
removeFrom
(WeakEntry<E>[] table, int removeAt) Removes this entry from the given table of entries.(package private) static int
upperCapacityThreshold
(int capacity) If the number of elements is upper than this threshold, then the table should be rehashed for better performance.Methods inherited from class java.lang.ref.Reference
clear, clone, enqueue, get, isEnqueued, reachabilityFence, refersTo
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sis.util.Disposable
dispose
-
Field Details
-
MIN_CAPACITY
static final int MIN_CAPACITYMinimal capacity for the internal table of entries. Must be a prime number.- See Also:
-
HASH_MASK
static final int HASH_MASKThe mask to apply on hash code values for ensuring positive values.- See Also:
-
REHASH_DELAY
static final long REHASH_DELAYNumber of nanoseconds to wait before to rehash the table for reducing its size. When the garbage collector collects a lot of elements, we will wait at least this amount of time before to rehash the tables, in case lot of news elements are going to be added. We noticed that in the absence of delay, there is a lot of "reduce", "expand", "reduce", "expand", etc. cycles.- See Also:
-
LOGGER
The logger where to logs collection events, if logging at the finest level is enabled. -
next
The next entry, ornull
if there is none. This is used when more than one entry has the same hash code value. -
hash
final int hashThe absolute value of the hash value of the referenced object.
-
-
Constructor Details
-
WeakEntry
Constructs a new weak reference.
-
-
Method Details
-
count
Counts the number of entries in the given table. This method does not verify if the referenced object has been garbage collected.- Type Parameters:
E
- the type of elements in the collection.- Parameters:
table
- the table in which to count the number of entries.- Returns:
- number of entries in the given table.
-
removeFrom
Removes this entry from the given table of entries.- Parameters:
table
- the table from which to remove this entry.removeAt
- the index of this entry in the given table.- Returns:
true
if this entry has been found and removed, orfalse
otherwise.
-
rehash
Rehashes the given table.- Parameters:
oldTable
- the table to rehash.count
- number of elements in the table (including chained elements).callerMethod
- the method invoking this one, for logging purpose only. The caller class will be inferred from the enclosing class of theoldTable
component type. This uses the knowledge that all our implementations ofWeakEntry
are inner classes.- Returns:
- the new table array, or
oldTable
if no rehash were needed.
-
lowerCapacityThreshold
static int lowerCapacityThreshold(int capacity) If the number of elements is lower than this threshold, then the table should be rehashed for saving space.- Parameters:
capacity
- the table capacity.- Returns:
- minimal number of elements for not rehashing.
-
upperCapacityThreshold
static int upperCapacityThreshold(int capacity) If the number of elements is upper than this threshold, then the table should be rehashed for better performance.- Parameters:
capacity
- the table capacity.- Returns:
- maximal number of elements for not rehashing.
-