Top Description Fields Constructors Methods
org.glassfish.pfl.dynamic.copyobject.impl

public Class FastCache<K, V>

extends AbstractMap<K, V>
Class Inheritance
Imports
java.util.AbstractMap, .Map, .Set

A cache intended to help speed up access to a Map. The idea is that some maps have a few values that are retrieved more frequently than others. So, we create a fixed size array that holds keys and values, and do a very fast hash on the key's identityHashCode. The cache is backed by a map, which can be an IdentityHashMap, or any other map (such as a WeakHashMap) where the keys satisfy k1.equals(k2) implies k1 == k2. Note that all put operations MUST go through this class, because calling put on the underlying map can result in the cache returning incorrect results for get.

Field Summary

Modifier and TypeField and Description
private long
private Object[]
private Map<K, V>
public static final int
private long
private Object[]

Constructor Summary

AccessConstructor and Description
public
FastCache(Map<K, V> map)

Method Summary

Modifier and TypeMethod and Description
public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public V
get(Object key)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public long
public long
private int
hash(Object key)

public V
put(K key, V value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Put the key and value in the cache and the underlying map.

Inherited from java.util.AbstractMap:
clearclonecontainsKeycontainsValueequalshashCodeisEmptykeySetputAllremovesizetoStringvalues

Field Detail

cacheCountback to summary
private long cacheCount
keysback to summary
private Object[] keys
mapback to summary
private Map<K, V> map
TABLE_SIZEback to summary
public static final int TABLE_SIZE
totalCountback to summary
private long totalCount
valuesback to summary
private Object[] values

Hides java.util.AbstractMap.values.

Constructor Detail

FastCacheback to summary
public FastCache(Map<K, V> map)

Method Detail

entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Annotations
@Override
getback to summary
public V get(Object key)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Doc from java.util.AbstractMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that Objects.equals(key, k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Annotations
@Override
@SuppressWarnings:unchecked
getCacheCountback to summary
public long getCacheCount()
getTotalCountback to summary
public long getTotalCount()
hashback to summary
private int hash(Object key)
putback to summary
public V put(K key, V value)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Put the key and value in the cache and the underlying map. This writes through to the map, rather than first storing a value in the cache which is only written as required, because that makes it easier to preserve the correct behavior of the map.

Annotations
@Override