Class LazyLoadingCachingMap<K,​V>

  • Type Parameters:
    K - the key type.
    V - the value type.

    public abstract class LazyLoadingCachingMap<K,​V>
    extends java.lang.Object
    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

      Constructors 
      Modifier Constructor Description
      protected LazyLoadingCachingMap​(Lock lock, java.lang.Class<V> valueClass)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes any cached map of values and restores the map to its initial state.
      V get​(K key)
      Retrieves the value for the given key.
      protected abstract java.util.Map<K,​V> loadMap()
      This method will reload the map data from scratch.
      void put​(K key, V value)
      Adds the key,value pair to the map.
      void remove​(K key)
      Removes the key,value pair from the map as specified by the given key.
      V[] valuesToArray()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LazyLoadingCachingMap

        protected LazyLoadingCachingMap​(Lock lock,
                                        java.lang.Class<V> valueClass)
    • Method Detail

      • loadMap

        protected abstract java.util.Map<K,​V> loadMap()
        This method will reload the map data from scratch.
        Returns:
        a map containing all current key, value pairs.
      • put

        public void put​(K key,
                        V value)
        Adds the key,value pair to the map. If the map is not loaded, this method will do nothing.
        Parameters:
        key - the key
        value - the value that is associated with the key.
      • remove

        public void remove​(K key)
        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

        public V get​(K key)
        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.
      • valuesToArray

        public V[] valuesToArray()