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

abstract class WeakEntry<E> extends WeakReference<E> implements Disposable
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

    Fields
    Modifier and Type
    Field
    Description
    (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.
    (package private) WeakEntry<E>
    The next entry, or null 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
    Constructor
    Description
    WeakEntry(E obj, WeakEntry<E> next, int hash)
    Constructs a new weak reference.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static <E> int
    count(WeakEntry<E>[] table)
    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>[]
    rehash(WeakEntry<E>[] oldTable, int count, String callerMethod)
    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_CAPACITY
      Minimal capacity for the internal table of entries. Must be a prime number.
      See Also:
    • HASH_MASK

      static final int HASH_MASK
      The mask to apply on hash code values for ensuring positive values.
      See Also:
    • REHASH_DELAY

      static final long REHASH_DELAY
      Number 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

      private static final Logger LOGGER
      The logger where to logs collection events, if logging at the finest level is enabled.
    • next

      WeakEntry<E> next
      The next entry, or null if there is none. This is used when more than one entry has the same hash code value.
    • hash

      final int hash
      The absolute value of the hash value of the referenced object.
  • Constructor Details

    • WeakEntry

      WeakEntry(E obj, WeakEntry<E> next, int hash)
      Constructs a new weak reference.
  • Method Details

    • count

      static <E> int count(WeakEntry<E>[] table)
      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

      final boolean removeFrom(WeakEntry<E>[] table, int removeAt)
      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, or false otherwise.
    • rehash

      static <E> WeakEntry<E>[] rehash(WeakEntry<E>[] oldTable, int count, String callerMethod)
      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 the oldTable component type. This uses the knowledge that all our implementations of WeakEntry 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.