Package ints

Class IndexArray

  • All Implemented Interfaces:
    IntArray

    public class IndexArray
    extends java.lang.Object
    implements IntArray

    Class IndexArray stores an array whose entries are elements of a bounded set of non-negative integers along with an upper bound. Both the stored array and upper bound are specified at the time of object construction. It is the client code that constructs a IndexArray object's responsibility to ensure that the bound specified at construction is correct. The contract for this class is undefined if the bound is specified at object construction is incorrect. It is recommended that the bound be the minimum integer that is greater than all elements in the stored array, but not is not a requirement.

    Instances of class IndexArray are immutable.

    • Constructor Summary

      Constructors 
      Constructor Description
      IndexArray​(int[] intArray, int valueSize)
      Constructs a new IndexArray instance from the specified data.
      IndexArray​(IntArray intArray, int valueSize)
      Constructs a new IndexArray instance from the specified data.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int get​(int index)
      Returns the specified array element.
      IntArray intArray()
      Returns the wrapped IntArray object.
      int size()
      Returns the number of elements in this IntArray.
      int valueSize()
      Returns the value size that was specified at construction.
      static int valueSize​(int[] ia)
      Returns the minimum integer that is greater than all elements in the specified array of non-negative values.
      static int valueSize​(IntArray ia)
      Returns the minimum integer that is greater than all elements in the specified list of non-negative values.
      • Methods inherited from class java.lang.Object

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

      • IndexArray

        public IndexArray​(int[] intArray,
                          int valueSize)
        Constructs a new IndexArray instance from the specified data. The contract for this constructor and class is unspecified if the sequence indices are not a subset of 0, 1, ..., (valueSize - 1).
        Parameters:
        intArray - an array with non-negative values
        valueSize - a value that is greater than all elements of the specified array
        Throws:
        java.lang.NullPointerException - if IndexArray == null
      • IndexArray

        public IndexArray​(IntArray intArray,
                          int valueSize)
        Constructs a new IndexArray instance from the specified data. The contract for this constructor and class is unspecified if the sequence indices are not a subset of 0, 1, ..., (valueSize - 1).
        Parameters:
        intArray - an array with non-negative values
        valueSize - a value that is greater than all elements of the specified array
        Throws:
        java.lang.NullPointerException - if IndexArray == null
    • Method Detail

      • get

        public int get​(int index)
        Description copied from interface: IntArray
        Returns the specified array element.
        Specified by:
        get in interface IntArray
        Parameters:
        index - an array index
        Returns:
        the specified array element
      • size

        public int size()
        Description copied from interface: IntArray
        Returns the number of elements in this IntArray.
        Specified by:
        size in interface IntArray
        Returns:
        the number of elements in this IntArray
      • valueSize

        public int valueSize()
        Returns the value size that was specified at construction.
        Returns:
        the value size that was specified at construction
      • intArray

        public IntArray intArray()
        Returns the wrapped IntArray object.
        Returns:
        the wrapped IntArray object
      • valueSize

        public static int valueSize​(int[] ia)
        Returns the minimum integer that is greater than all elements in the specified array of non-negative values.
        Parameters:
        ia - an array of non-negative values
        Returns:
        the minimum integer that is greater than all elements in the specified array of non-negative values
        Throws:
        java.lang.IllegalArgumentException - if any element of the specified array is negative
      • valueSize

        public static int valueSize​(IntArray ia)
        Returns the minimum integer that is greater than all elements in the specified list of non-negative values.
        Parameters:
        ia - an array of non-negative values
        Returns:
        the minimum integer that is greater than all elements in the specified array of non-negative values
        Throws:
        java.lang.IllegalArgumentException - if any element of the specified array is negative