| java.lang.Object java.util.AbstractMap org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap
ConcurrentReferenceHashMap | public class ConcurrentReferenceHashMap extends AbstractMap implements ConcurrentMap,ReferenceMap,SizedMap,Cloneable(Code) | | This class implements a HashMap which has limited synchronization
and reference keys or values(but not both). In particular mutators are
generally synchronized while accessors are generally not. Additionally the
Iterators returned by this class are not "fail-fast", but instead try to
continue to iterate over the data structure after changes have been
made. Finally purging of the reference queue is only done inside mutators.
Null keys are not supported if keys use references. Null values are not
supported if values use references.
This class is based heavily on the WeakHashMap class in the Java
collections package.
|
Field Summary | |
final static double[] | RANDOMS Cache of random numbers used in "random" methods, since generating them
is expensive. |
Constructor Summary | |
public | ConcurrentReferenceHashMap(int keyType, int valueType, int initialCapacity, float loadFactor) Constructs a new, empty HashMap with the specified initial
capacity and the specified load factor. | public | ConcurrentReferenceHashMap(int keyType, int valueType, int initialCapacity) Constructs a new, empty HashMap with the specified initial capacity
and default load factor. | public | ConcurrentReferenceHashMap(int keyType, int valueType) Constructs a new, empty HashMap with a default capacity and load factor. | public | ConcurrentReferenceHashMap(int keyType, int valueType, Map t) Constructs a new HashMap with the same mappings as the given
Map. |
Method Summary | |
int | capacity() | public synchronized void | clear() Removes all mappings from this HashMap. | public synchronized Object | clone() Returns a shallow copy of this HashMap. | public boolean | containsKey(Object key) Returns true if this HashMap contains a mapping for the specified key. | public boolean | containsValue(Object value) Returns true if this HashMap maps one or more keys to the specified
value. | public Set | entrySet() Returns a Collection view of the mappings contained in this HashMap.
Each element in the returned collection is a Map.Entry. | protected boolean | eq(Object x, Object y) Compare two objects. | public Object | get(Object key) Returns the value to which this HashMap maps the specified key. | public int | getMaxSize() | protected int | hc(Object o) Obtain the hashcode of an object. | public boolean | isEmpty() Returns true if this Map contains no key-value mappings. | public boolean | isFull() | public void | keyExpired(Object value) | public Set | keySet() Returns a Set view of the keys contained in this HashMap. | float | loadFactor() | public void | overflowRemoved(Object key, Object value) | public Object | put(Object key, Object value) Associates the specified value with the specified key in this HashMap.
If the HashMap previously contained a mapping for this key, the old
value is replaced.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. | public void | putAll(Map t) Copies all of the mappings from the specified Map to this HashMap
These mappings will replace any mappings that this HashMap had for any
of the keys currently in the specified Map. | public Iterator | randomEntryIterator() | public Object | remove(Object key) Removes the mapping for this key from this HashMap if present.
Parameters: key - key whose mapping is to be removed from the Map. | public void | removeExpired() | public Map.Entry | removeRandom() | public void | setMaxSize(int maxSize) | public int | size() Returns the number of key-value mappings in this Map. | public void | valueExpired(Object key) | public Collection | values() Returns a Collection view of the values contained in this HashMap.
The Collection is backed by the HashMap, so changes to the HashMap are
reflected in the Collection, and vice-versa. |
RANDOMS | final static double[] RANDOMS(Code) | | Cache of random numbers used in "random" methods, since generating them
is expensive. We hope each map changes enough between cycling through
this list that the overall effect is random enough.
|
ConcurrentReferenceHashMap | public ConcurrentReferenceHashMap(int keyType, int valueType, int initialCapacity, float loadFactor)(Code) | | Constructs a new, empty HashMap with the specified initial
capacity and the specified load factor.
Parameters: keyType - the reference type of map keys Parameters: valueType - the reference type of map values Parameters: initialCapacity - the initial capacity of the HashMap. Parameters: loadFactor - a number between 0.0 and 1.0. throws: IllegalArgumentException - if neither keys nor values use hardreferences, if the initial capacity is less than or equal to zero, or ifthe load factor is less than or equal to zero |
ConcurrentReferenceHashMap | public ConcurrentReferenceHashMap(int keyType, int valueType, int initialCapacity)(Code) | | Constructs a new, empty HashMap with the specified initial capacity
and default load factor.
Parameters: keyType - the reference type of map keys Parameters: valueType - the reference type of map values Parameters: initialCapacity - the initial capacity of the HashMap. |
ConcurrentReferenceHashMap | public ConcurrentReferenceHashMap(int keyType, int valueType)(Code) | | Constructs a new, empty HashMap with a default capacity and load factor.
Parameters: keyType - the reference type of map keys Parameters: valueType - the reference type of map values |
ConcurrentReferenceHashMap | public ConcurrentReferenceHashMap(int keyType, int valueType, Map t)(Code) | | Constructs a new HashMap with the same mappings as the given
Map. The HashMap is created with a capacity of thrice the number
of entries in the given Map or 11 (whichever is greater), and a
default load factor.
Parameters: keyType - the reference type of map keys Parameters: valueType - the reference type of map values |
clear | public synchronized void clear()(Code) | | Removes all mappings from this HashMap.
|
clone | public synchronized Object clone()(Code) | | Returns a shallow copy of this HashMap. The keys and values
themselves are not cloned.
|
containsKey | public boolean containsKey(Object key)(Code) | | Returns true if this HashMap contains a mapping for the specified key.
Parameters: key - key whose presence in this Map is to be tested. |
containsValue | public boolean containsValue(Object value)(Code) | | Returns true if this HashMap maps one or more keys to the specified
value.
Parameters: value - value whose presence in this Map is to be tested. |
entrySet | public Set entrySet()(Code) | | Returns a Collection view of the mappings contained in this HashMap.
Each element in the returned collection is a Map.Entry. The Collection
is backed by the HashMap, so changes to the HashMap are reflected in the
Collection, and vice-versa. The Collection supports element removal,
which removes the corresponding mapping from the HashMap, via the
Iterator.remove, Collection.remove, removeAll, retainAll and clear
operations. It does not support the add or addAll operations.
See Also: Map.Entry |
eq | protected boolean eq(Object x, Object y)(Code) | | Compare two objects. These might be keys, values, or Entry instances.
This implementation uses a normal null-safe object equality algorithm.
since: 1.0.0 |
get | public Object get(Object key)(Code) | | Returns the value to which this HashMap maps the specified key.
Returns null if the HashMap contains no mapping for this key.
Parameters: key - key whose associated value is to be returned. |
getMaxSize | public int getMaxSize()(Code) | | |
hc | protected int hc(Object o)(Code) | | Obtain the hashcode of an object. The object might be a key, a value,
or an Entry. This implementation just delegates to
Object.hashCode since: 1.0.0 |
isEmpty | public boolean isEmpty()(Code) | | Returns true if this Map contains no key-value mappings. This
result is a snapshot, and may not reflect unprocessed entries
that will be removed before next attempted access because they
are no longer referenced.
|
isFull | public boolean isFull()(Code) | | |
keySet | public Set keySet()(Code) | | Returns a Set view of the keys contained in this HashMap. The Set is
backed by the HashMap, so changes to the HashMap are reflected in the
Set, and vice-versa. The Set supports element removal, which removes
the corresponding mapping from the HashMap, via the Iterator.remove,
Set.remove, removeAll retainAll, and clear operations. It does not
support the add or addAll operations.
|
loadFactor | float loadFactor()(Code) | | |
put | public Object put(Object key, Object value)(Code) | | Associates the specified value with the specified key in this HashMap.
If the HashMap previously contained a mapping for this key, the old
value is replaced.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. previous value associated with specified key, or null if therewas no mapping for key. A null return can also indicate thatthe HashMap previously associated null with the specified key. |
putAll | public void putAll(Map t)(Code) | | Copies all of the mappings from the specified Map to this HashMap
These mappings will replace any mappings that this HashMap had for any
of the keys currently in the specified Map.
Parameters: t - Mappings to be stored in this Map. |
remove | public Object remove(Object key)(Code) | | Removes the mapping for this key from this HashMap if present.
Parameters: key - key whose mapping is to be removed from the Map. previous value associated with specified key, or null if therewas no mapping for key. A null return can also indicate thatthe HashMap previously associated null with the specified key. |
removeExpired | public void removeExpired()(Code) | | |
setMaxSize | public void setMaxSize(int maxSize)(Code) | | |
size | public int size()(Code) | | Returns the number of key-value mappings in this Map. This
result is a snapshot, and may not reflect unprocessed entries
that will be removed before next attempted access because they
are no longer referenced.
|
values | public Collection values()(Code) | | Returns a Collection view of the values contained in this HashMap.
The Collection is backed by the HashMap, so changes to the HashMap are
reflected in the Collection, and vice-versa. The Collection supports
element removal, which removes the corresponding mapping from the
HashMap, via the Iterator.remove, Collection.remove, removeAll,
retainAll and clear operations. It does not support the add or addAll
operations.
|
|
|