Class ReferenceHashMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.apache.openjpa.lib.util.collections.AbstractHashedMap<K,V>
-
- org.apache.openjpa.lib.util.collections.AbstractReferenceMap<K,V>
-
- org.apache.openjpa.lib.util.collections.ReferenceMap
-
- org.apache.openjpa.lib.util.ReferenceHashMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Map
,IterableMap
,ReferenceMap
,SizedMap
public class ReferenceHashMap extends ReferenceMap implements ReferenceMap, SizedMap
Map in which the key, value, or both may be weak/soft references.- Since:
- 0.4.0
- Author:
- Abe White
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.openjpa.lib.util.collections.AbstractReferenceMap
AbstractReferenceMap.ReferenceEntry<K,V>, AbstractReferenceMap.ReferenceStrength
-
Nested classes/interfaces inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
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>
-
-
Field Summary
-
Fields inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
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 Summary
Constructors Constructor Description ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType)
ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType, int capacity, float loadFactor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addMapping(int hashIndex, int hashCode, java.lang.Object key, java.lang.Object value)
Adds a new key-value mapping into this map.protected AbstractReferenceMap.ReferenceEntry
createEntry(AbstractHashedMap.HashEntry next, int hashCode, java.lang.Object key, java.lang.Object value)
Creates a ReferenceEntry instead of a HashEntry.protected void
doReadObject(java.io.ObjectInputStream in)
Replaces the superclass method to read the state of this class.protected void
doWriteObject(java.io.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(java.lang.Object value)
Overridable callback for when a key reference expires.void
overflowRemoved(java.lang.Object key, java.lang.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(java.lang.Object key)
Overridable callback for when a value reference expires.-
Methods inherited from class org.apache.openjpa.lib.util.collections.AbstractReferenceMap
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
-
Methods inherited from class org.apache.openjpa.lib.util.collections.AbstractHashedMap
addEntry, calculateNewCapacity, calculateThreshold, checkCapacity, clone, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entryValue, equals, hash, hashCode, hashIndex, isEqualValue, putAll, removeEntry, removeMapping, reuseEntry, toString, updateEntry
-
-
-
-
Constructor Detail
-
ReferenceHashMap
public ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType)
-
ReferenceHashMap
public ReferenceHashMap(AbstractReferenceMap.ReferenceStrength keyType, AbstractReferenceMap.ReferenceStrength valueType, int capacity, float loadFactor)
-
-
Method Detail
-
getMaxSize
public int getMaxSize()
Description copied from interface:SizedMap
The maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
getMaxSize
in interfaceSizedMap
-
setMaxSize
public void setMaxSize(int maxSize)
Description copied from interface:SizedMap
The maximum number of entries, or Integer.MAX_VALUE for no limit.- Specified by:
setMaxSize
in interfaceSizedMap
-
isFull
public boolean isFull()
Description copied from interface:SizedMap
Whether the map is full.
-
overflowRemoved
public void overflowRemoved(java.lang.Object key, java.lang.Object value)
Description copied from interface:SizedMap
Overridable callback for when an overflow entry is automatically removed.- Specified by:
overflowRemoved
in interfaceSizedMap
-
valueExpired
public void valueExpired(java.lang.Object key)
Description copied from interface:ReferenceMap
Overridable callback for when a value reference expires.- Specified by:
valueExpired
in interfaceReferenceMap
- Parameters:
key
- the key for the expired value
-
keyExpired
public void keyExpired(java.lang.Object value)
Description copied from interface:ReferenceMap
Overridable callback for when a key reference expires.- Specified by:
keyExpired
in interfaceReferenceMap
- Parameters:
value
- the value for the expired key
-
removeExpired
public void removeExpired()
Description copied from interface:ReferenceMap
Purge stale entries.- Specified by:
removeExpired
in interfaceReferenceMap
-
addMapping
protected void addMapping(int hashIndex, int hashCode, java.lang.Object key, java.lang.Object value)
Description copied from class:AbstractHashedMap
Adds a new key-value mapping into this map.This implementation calls
createEntry()
,addEntry()
andcheckCapacity()
. It also handles changes tomodCount
andsize
. Subclasses could override to fully control adds to the map.- Overrides:
addMapping
in classAbstractHashedMap
- Parameters:
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 add
-
createEntry
protected AbstractReferenceMap.ReferenceEntry createEntry(AbstractHashedMap.HashEntry next, int hashCode, java.lang.Object key, java.lang.Object value)
Description copied from class:AbstractReferenceMap
Creates a ReferenceEntry instead of a HashEntry.- Overrides:
createEntry
in classAbstractReferenceMap
- Parameters:
next
- the next entry in sequencehashCode
- the hash code to usekey
- the key to storevalue
- the value to store- Returns:
- the newly created entry
-
doWriteObject
protected void doWriteObject(java.io.ObjectOutputStream out) throws java.io.IOException
Description copied from class:AbstractReferenceMap
Replaces the superclass method to store the state of this class.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.
- Overrides:
doWriteObject
in classAbstractReferenceMap
- Parameters:
out
- the output stream- Throws:
java.io.IOException
- if an error occurs while writing to the stream
-
doReadObject
protected void doReadObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException
Description copied from class:AbstractReferenceMap
Replaces the superclass method to read the state of this class.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()
orcalculateThreshold()
will work correctly.- Overrides:
doReadObject
in classAbstractReferenceMap
- Parameters:
in
- the input stream- Throws:
java.lang.ClassNotFoundException
- if an object read from the stream can not be loadedjava.io.IOException
- if an error occurs while reading from the stream
-
-