Class ArrayMap

java.lang.Object
org.jibx.binding.util.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
  • Field Details

    • m_array

      private ArrayList m_array
      Array of values.
    • m_map

      private HashMap m_map
      Map from values to indices.
  • Constructor Details

    • ArrayMap

      public ArrayMap()
      Default constructor.
    • ArrayMap

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

    • 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