org.apache.commons.compress.harmony.unpack200

## Class SegmentConstantPoolArrayCache

- java.lang.Object
- - org.apache.commons.compress.harmony.unpack200.SegmentConstantPoolArrayCache

-     public class SegmentConstantPoolArrayCache
      extends Object

  The SegmentConstantPool spends a lot of time searching through large arrays of Strings looking for matches. This can be sped up by caching the arrays in HashMaps so the String keys are looked up and resolve to positions in the array rather than iterating through the arrays each time. Because the arrays only grow (never shrink or change) we can use the last known size as a way to determine if the array has changed. Note that this cache must be synchronized externally if it is shared.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `SegmentConstantPoolArrayCache.CachedArray` CachedArray 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 and Description
    --- | ---
    `protected IdentityHashMap<String[],SegmentConstantPoolArrayCache.CachedArray>` | `knownArrays`
    `protected String[]` | `lastArray`
    `protected List<Integer>` | `lastIndexes`
    `protected String` | `lastKey`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SegmentConstantPoolArrayCache()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `arrayIsCached(String[] array)` Given a String array, answer true if the array is correctly cached.
    `protected void` | `cacheArray(String[] array)` Cache the array passed in as the argument
    `List<Integer>` | `indexesForArrayKey(String[] array, String key)` Answer the indices for the given key in the given array.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### knownArrays

          protected IdentityHashMap<String[],SegmentConstantPoolArrayCache.CachedArray> knownArrays

    - #### lastIndexes

          protected List<Integer> lastIndexes

    - #### lastArray

          protected String[] lastArray

    - #### lastKey

          protected String lastKey

  - ### Constructor Detail

    - #### SegmentConstantPoolArrayCache

          public SegmentConstantPoolArrayCache()

  - ### Method Detail

    - #### arrayIsCached

          protected boolean arrayIsCached(String[] array)

      Given a String array, answer true if the array is correctly cached. Answer false if the array is not cached, or if the array cache is outdated.
      Parameters:
        `array` - of String
      Returns:
        boolean true if up-to-date cache, otherwise false.

    - #### cacheArray

          protected void cacheArray(String[] array)

      Cache the array passed in as the argument
      Parameters:
        `array` - String[] to cache

    - #### indexesForArrayKey

          public List<Integer> indexesForArrayKey(String[] array,
                                                  String key)

      Answer the indices for the given key in the given array. If no such key exists in the cached array, answer -1.
      Parameters:
        `array` - String[] array to search for the value
        `key` - String value for which to search
      Returns:
        List collection of index positions in the array

Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.