Class ResourceLimitedMap<Key,Value>

java.lang.Object
htsjdk.samtools.util.ResourceLimitedMap<Key,Value>
Direct Known Subclasses:
FileAppendStreamLRUCache

public class ResourceLimitedMap<Key,Value> extends Object
LRU collection class for managing objects that place some resource burden such that not too many of them can existing in the VM at one time, but they can be reconstructed ias necessary. Original motivation was for an LRU cache of FileOutputStreams.
  • Constructor Details

    • ResourceLimitedMap

      public ResourceLimitedMap(int cacheSize, ResourceLimitedMapFunctor<Key,Value> functor)
      Create LRU cache
      Parameters:
      cacheSize - Max number of objects to be stored in the cache.
      functor - Encapsulates methods for creating a new object if it isn't in the cache, and for finalizing an object that is getting LRU'ed out of the cache.
  • Method Details

    • get

      public Value get(Key key)
      Return an existing value, or create a new one if necessary. If creating a new one and the cache is full, the eldest object is pushed out of the cache.
      Parameters:
      key - Key of desired value.
      Returns:
      Either existing value, or new value created from key and inserted into map.
    • remove

      public Value remove(Key key)
    • containsKey

      public boolean containsKey(Key key)
      Determine if the map contains the given key. Note that even if the map does not contain the key, get(key) will return a value, because one will be created.
      Parameters:
      key -
      Returns:
      true if the map currently contains the given key. It is unknown whether the map may have contained the key in the past.
    • finalizeAll

      public void finalizeAll()
      Remove all the values from the map, and call functory.finalizeValue() on each of them.