Interface WeakHashClock<K,​V>

  • All Known Implementing Classes:
    WeakHashClockImpl

    public interface WeakHashClock<K,​V>
    This is a clock (if non-empty the next verb will always return a new value in a cycle) that can also get values in O(1) complexity. This HashClock also has Weak key references, so if the key becomes unavailable it will not be retrievable from the get operation and the next operation will remove it from the clock
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Sets the clock size back to zero, no entries
      void clearStaleReferences()
      Causes stale references to be cleared from the data structures.
      V get​(K key)
      Gets the given key, returning null if not found
      boolean hasWeakKeys()
      Tells if this WeakHashClock has Weak keys
      java.util.Map.Entry<K,​V> next()
      Returns the next key/value pair in the clock, or null if the clock has no members.
      void put​(K key, V value)
      Adds the given pair to the clock.
      void releaseMatching​(CacheKeyFilter<K> filter)
      Releases all key/value pairs that match the filter
      V remove​(K key)
      Removes the given key from the clock, if found
      int size()
      Returns the number of elements currently in the clock.
    • Method Detail

      • put

        void put​(K key,
                 V value)
        Adds the given pair to the clock. It will be placed at the current tail of the clock
        Parameters:
        key - Must not be null
        value - May not be null
      • get

        V get​(K key)
        Gets the given key, returning null if not found
        Parameters:
        key - The key to search for, may not be null
        Returns:
        The value found, or null if not found
      • remove

        V remove​(K key)
        Removes the given key from the clock, if found
        Parameters:
        key - The key to remove, may not be null
        Returns:
        The value removed if found, or null if not found
      • releaseMatching

        void releaseMatching​(CacheKeyFilter<K> filter)
        Releases all key/value pairs that match the filter
        Parameters:
        filter - A non-null filter that can be used to delete every key/value pair that matches the filter
      • size

        int size()
        Returns the number of elements currently in the clock. References that have gone away because they were weakly referenced will not be counted in the size
        Returns:
        The number of entries currently in the clock
      • next

        java.util.Map.Entry<K,​V> next()
        Returns the next key/value pair in the clock, or null if the clock has no members. This will advance the head and tail of the clock to the next element. If the WeakReference for the returned element is null then this element will also have been removed from the clock by this operation
        Returns:
        The next key/value pair in the
      • clear

        void clear()
        Sets the clock size back to zero, no entries
      • clearStaleReferences

        void clearStaleReferences()
        Causes stale references to be cleared from the data structures. Since this is a weak clock the references can go away at any time, which happens whenever any operation has been performed. However, it may be the case that no operation will be performed for a while and so this method is provided to have a no-op operation to call in order to clear out any stale references
      • hasWeakKeys

        boolean hasWeakKeys()
        Tells if this WeakHashClock has Weak keys
        Returns:
        true if this map has weak keys, true otherwise