Top Description Methods
org.glassfish.hk2.utilities.general

public Interface WeakHashClock<K, V>

Known Direct Implementers
org.glassfish.hk2.utilities.general.internal.WeakHashClockImpl
Imports
java.util.Map, org.glassfish.hk2.utilities.cache.CacheKeyFilter

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
Author
jwells

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Sets the clock size back to zero, no entries

public void
clearStaleReferences()

Causes stale references to be cleared from the data structures.

public V

Returns:

The value found, or null if not found
get
(K
The key to search for, may not be null
key
)

Gets the given key, returning null if not found

public boolean

Returns:

true if this map has weak keys, true otherwise
hasWeakKeys
()

Tells if this WeakHashClock has Weak keys

public Map.Entry<K, V>

Returns:

The next key/value pair in the
next
()

Returns the next key/value pair in the clock, or null if the clock has no members.

public void
put(K
Must not be null
key
,
V
May not be null
value
)

Adds the given pair to the clock.

public void
releaseMatching(CacheKeyFilter<K>
A non-null filter that can be used to delete every key/value pair that matches the filter
filter
)

Releases all key/value pairs that match the filter

public V

Returns:

The value removed if found, or null if not found
remove
(K
The key to remove, may not be null
key
)

Removes the given key from the clock, if found

public int

Returns:

The number of entries currently in the clock
size
()

Returns the number of elements currently in the clock.

Method Detail

clearback to summary
public void clear()

Sets the clock size back to zero, no entries

clearStaleReferencesback to summary
public 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

getback to summary
public V get(K key)

Gets the given key, returning null if not found

Parameters
key:K

The key to search for, may not be null

Returns:V

The value found, or null if not found

hasWeakKeysback to summary
public boolean hasWeakKeys()

Tells if this WeakHashClock has Weak keys

Returns:boolean

true if this map has weak keys, true otherwise

nextback to summary
public 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:Map.Entry<K, V>

The next key/value pair in the

putback to summary
public 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:K

Must not be null

value:V

May not be null

releaseMatchingback to summary
public void releaseMatching(CacheKeyFilter<K> filter)

Releases all key/value pairs that match the filter

Parameters
filter:CacheKeyFilter<K>

A non-null filter that can be used to delete every key/value pair that matches the filter

removeback to summary
public V remove(K key)

Removes the given key from the clock, if found

Parameters
key:K

The key to remove, may not be null

Returns:V

The value removed if found, or null if not found

sizeback to summary
public 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:int

The number of entries currently in the clock