Class SegmentConstantPoolArrayCache.CachedArray

  • Enclosing class:
    SegmentConstantPoolArrayCache

    protected class SegmentConstantPoolArrayCache.CachedArray
    extends java.lang.Object
    Keeps track of the last known size of an array as well as a HashMap that knows the mapping from element values to the indices of the array which contain that value.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int lastKnownSize  
      (package private) java.lang.String[] primaryArray  
      (package private) java.util.HashMap<java.lang.String,​java.util.List<java.lang.Integer>> primaryTable  
    • Constructor Summary

      Constructors 
      Constructor Description
      CachedArray​(java.lang.String[] array)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void cacheIndexes()
      Given a primaryArray, cache its values in a HashMap to provide a backwards mapping from element values to element indexes.
      java.util.List<java.lang.Integer> indexesForKey​(java.lang.String key)
      Given a particular key, answer a List of index locations in the array which contain that key.
      int lastKnownSize()
      Answer the last known size of the array cached.
      • Methods inherited from class java.lang.Object

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

      • primaryArray

        java.lang.String[] primaryArray
      • lastKnownSize

        int lastKnownSize
      • primaryTable

        java.util.HashMap<java.lang.String,​java.util.List<java.lang.Integer>> primaryTable
    • Constructor Detail

      • CachedArray

        public CachedArray​(java.lang.String[] array)
    • Method Detail

      • cacheIndexes

        protected void cacheIndexes()
        Given a primaryArray, cache its values in a HashMap to provide a backwards mapping from element values to element indexes. For instance, a primaryArray of: {"Zero", "Foo", "Two", "Foo"} would yield a HashMap of: "Zero" -> 0 "Foo" -> 1, 3 "Two" -> 2 which is then cached.
      • indexesForKey

        public java.util.List<java.lang.Integer> indexesForKey​(java.lang.String key)
        Given a particular key, answer a List of index locations in the array which contain that key. If no elements are found, answer an empty list.
        Parameters:
        key - String element of the array
        Returns:
        List of indexes containing that key in the array.
      • lastKnownSize

        public int lastKnownSize()
        Answer the last known size of the array cached. If the last known size is not the same as the current size, the array must have changed.
        Returns:
        int last known size of the cached array