Package ghidra.program.database.data
Class LazyLoadingCachingMap<K,V>
java.lang.Object
ghidra.program.database.data.LazyLoadingCachingMap<K,V>
- Type Parameters:
K
- the key type.V
- the value type.
Instances of this class will provide a simple map interface to a cached set of key,value
pairs. This class requires that the map can be generated from scratch at any time and
that adding/removing items from this map is just a mirroring of those changes elsewhere.
This map is lazy in that it won't load the data until needed and it will use a soft reference
to maintain the map until such time as the java garbage collector decides to reclaim it.
This class uses a ghidra Lock object to coordinate threaded access when loading the underlying map data. It manages both the lock and its own synchronization to avoid race conditions and deadlocks.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes any cached map of values and restores the map to its initial state.Retrieves the value for the given key.getMap()
Note: this map is always called from either a synchronized block or code holding the "lock".loadMap()
This method will reload the map data from scratch.void
Adds the key,value pair to the map.void
Removes the key,value pair from the map as specified by the given key.values()
Returns an unmodifiable view of the values in this map.
-
Constructor Details
-
LazyLoadingCachingMap
-
-
Method Details
-
loadMap
This method will reload the map data from scratch. Subclass may assume that the database lock has been acquired.- Returns:
- a map containing all current key, value pairs.
-
put
Adds the key,value pair to the map. If the map is not loaded, this method will do nothing.- Parameters:
key
- the keyvalue
- the value that is associated with the key.
-
remove
Removes the key,value pair from the map as specified by the given key. If the map is currently not loaded, this method will do nothing.- Parameters:
key
- the key to remove from the map.
-
clear
public void clear()Removes any cached map of values and restores the map to its initial state. -
get
Retrieves the value for the given key. This will currently load the map if not already loaded.- Parameters:
key
- the key for whose value to retrieve.- Returns:
- the value for the given key.
-
values
Returns an unmodifiable view of the values in this map.- Returns:
- an unmodifiable view of the values in this map.
-
getMap
Note: this map is always called from either a synchronized block or code holding the "lock".- Returns:
- the underlying map of key,value pairs or null if it is currently not loaded.
-