Class ArrayMap


  • public class ArrayMap
    extends Object
    Array with reverse mapping from values to indices. This operates as the combination of an array with ordinary int indices and a hashmap from values back to the corresponding index position. Values are assured to be unique.
    Author:
    Dennis M. Sosnoski
    • Constructor Detail

      • ArrayMap

        public ArrayMap()
        Default constructor.
      • ArrayMap

        public ArrayMap​(int size)
        Constructor with initial capacity supplied.
        Parameters:
        size - initial capacity for array map
    • Method Detail

      • get

        public Object get​(int index)
        Get value for index. The index must be within the valid range (from 0 to one less than the number of values present).
        Parameters:
        index - number to be looked up
        Returns:
        value at that index position
      • find

        public int find​(Object obj)
        Find existing object. If the supplied value object is present in the array map its index position is returned.
        Parameters:
        obj - value to be found
        Returns:
        index number assigned to value, or -1 if not found
      • findOrAdd

        public int findOrAdd​(Object obj)
        Add object. If the supplied value object is already present in the array map the existing index position is returned.
        Parameters:
        obj - value to be added
        Returns:
        index number assigned to value
      • size

        public int size()
        Get count of values present.
        Returns:
        number of values in array map