public class ReferenceHashMap extends ReferenceMap implements ReferenceMap, SizedMap
AbstractReferenceMap.ReferenceEntry<K,V>, AbstractReferenceMap.ReferenceStrength
AbstractHashedMap.EntrySet<K,V>, AbstractHashedMap.EntrySetIterator<K,V>, AbstractHashedMap.HashEntry<K,V>, AbstractHashedMap.HashIterator<K,V>, AbstractHashedMap.HashMapIterator<K,V>, AbstractHashedMap.KeySet<K>, AbstractHashedMap.KeySetIterator<K>, AbstractHashedMap.Values<V>, AbstractHashedMap.ValuesIterator<V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID
Constructor and Description |
---|
ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType,
AbstractReferenceMap.ReferenceStrength valueType) |
ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType,
AbstractReferenceMap.ReferenceStrength valueType,
int capacity,
float loadFactor) |
Modifier and Type | Method and Description |
---|---|
protected void |
addMapping(int hashIndex,
int hashCode,
Object key,
Object value)
Adds a new key-value mapping into this map.
|
protected AbstractReferenceMap.ReferenceEntry |
createEntry(AbstractHashedMap.HashEntry next,
int hashCode,
Object key,
Object value)
Creates a ReferenceEntry instead of a HashEntry.
|
protected void |
doReadObject(ObjectInputStream in)
Replaces the superclass method to read the state of this class.
|
protected void |
doWriteObject(ObjectOutputStream out)
Replaces the superclass method to store the state of this class.
|
int |
getMaxSize()
The maximum number of entries, or Integer.MAX_VALUE for no limit.
|
boolean |
isFull()
Whether the map is full.
|
void |
keyExpired(Object value)
Overridable callback for when a key reference expires.
|
void |
overflowRemoved(Object key,
Object value)
Overridable callback for when an overflow entry is automatically removed.
|
void |
removeExpired()
Purge stale entries.
|
void |
setMaxSize(int maxSize)
The maximum number of entries, or Integer.MAX_VALUE for no limit.
|
void |
valueExpired(Object key)
Overridable callback for when a value reference expires.
|
clear, containsKey, containsValue, createEntrySetIterator, createKeySetIterator, createValuesIterator, entrySet, get, getEntry, hashEntry, init, isEmpty, isEqualKey, isKeyType, isValueType, keySet, mapIterator, purge, purge, purgeBeforeRead, purgeBeforeWrite, put, remove, size, values
addEntry, calculateNewCapacity, calculateThreshold, checkCapacity, clone, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entryValue, equals, hash, hashCode, hashIndex, isEqualValue, putAll, removeEntry, removeMapping, reuseEntry, toString, updateEntry
finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
public ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType)
public ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType, int capacity, float loadFactor)
public int getMaxSize()
SizedMap
getMaxSize
in interface SizedMap
public void setMaxSize(int maxSize)
SizedMap
setMaxSize
in interface SizedMap
public boolean isFull()
SizedMap
public void overflowRemoved(Object key, Object value)
SizedMap
overflowRemoved
in interface SizedMap
public void valueExpired(Object key)
ReferenceMap
valueExpired
in interface ReferenceMap
key
- the key for the expired valuepublic void keyExpired(Object value)
ReferenceMap
keyExpired
in interface ReferenceMap
value
- the value for the expired keypublic void removeExpired()
ReferenceMap
removeExpired
in interface ReferenceMap
protected void addMapping(int hashIndex, int hashCode, Object key, Object value)
AbstractHashedMap
This implementation calls createEntry()
, addEntry()
and checkCapacity()
.
It also handles changes to modCount
and size
.
Subclasses could override to fully control adds to the map.
addMapping
in class AbstractHashedMap
hashIndex
- the index into the data array to store athashCode
- the hash code of the key to addkey
- the key to addvalue
- the value to addprotected AbstractReferenceMap.ReferenceEntry createEntry(AbstractHashedMap.HashEntry next, int hashCode, Object key, Object value)
AbstractReferenceMap
createEntry
in class AbstractReferenceMap
next
- the next entry in sequencehashCode
- the hash code to usekey
- the key to storevalue
- the value to storeprotected void doWriteObject(ObjectOutputStream out) throws IOException
AbstractReferenceMap
Serialization is not one of the JDK's nicest topics. Normal serialization will
initialise the superclass before the subclass. Sometimes however, this isn't
what you want, as in this case the put()
method on read can be
affected by subclass state.
The solution adopted here is to serialize the state data of this class in
this protected method. This method must be called by the
writeObject()
of the first serializable subclass.
Subclasses may override if they have a specific field that must be present on read before this implementation will work. Generally, the read determines what must be serialized here, if anything.
doWriteObject
in class AbstractReferenceMap
out
- the output streamIOException
- if an error occurs while writing to the streamprotected void doReadObject(ObjectInputStream in) throws ClassNotFoundException, IOException
AbstractReferenceMap
Serialization is not one of the JDK's nicest topics. Normal serialization will
initialise the superclass before the subclass. Sometimes however, this isn't
what you want, as in this case the put()
method on read can be
affected by subclass state.
The solution adopted here is to deserialize the state data of this class in
this protected method. This method must be called by the
readObject()
of the first serializable subclass.
Subclasses may override if the subclass has a specific field that must be present
before put()
or calculateThreshold()
will work correctly.
doReadObject
in class AbstractReferenceMap
in
- the input streamClassNotFoundException
- if an object read from the stream can not be loadedIOException
- if an error occurs while reading from the streamCopyright © 2006–2022 Apache Software Foundation. All rights reserved.