Package ints

Class WrappedIntArray

  • All Implemented Interfaces:
    IntArray

    public final class WrappedIntArray
    extends java.lang.Object
    implements IntArray

    Class WrappedIntArray represents an immutable int[] array.

    Instances of WrappedIntArray are immutable.
    • Constructor Summary

      Constructors 
      Constructor Description
      WrappedIntArray​(int[] ia)
      Constructs a new WrappedIntArray instance.
      WrappedIntArray​(int[] ia, int valueSize)
      Constructs a new WrappedIntArray instance.
      WrappedIntArray​(IntList il)
      Constructs a new WrappedIntArray instance.
      WrappedIntArray​(IntList il, int valueSize)
      Constructs a new WrappedIntArray instance.
      WrappedIntArray​(java.util.stream.IntStream values)
      Constructs an WrappedIntrray object with the specified values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int binarySearch​(int key)
      Searches this for the specified value using the binary search algorithm.
      int binarySearch​(int fromIndex, int toIndex, int key)
      Searches the specified range of this for the specified value using the binary search algorithm.
      int get​(int index)
      Returns the specified array element.
      int size()
      Returns the number of elements in this IntArray.
      int[] toArray()
      Returns the list of integers.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • WrappedIntArray

        public WrappedIntArray​(int[] ia)
        Constructs a new WrappedIntArray instance.
        Parameters:
        ia - an array of integers
        Throws:
        java.lang.NullPointerException - if ia == null
      • WrappedIntArray

        public WrappedIntArray​(java.util.stream.IntStream values)
        Constructs an WrappedIntrray object with the specified values.
        Parameters:
        values - a stream of integer values
        Throws:
        java.lang.NullPointerException - if values == null
        java.lang.IllegalStateException - if the stream has previously been used
      • WrappedIntArray

        public WrappedIntArray​(int[] ia,
                               int valueSize)
        Constructs a new WrappedIntArray instance.
        Parameters:
        ia - an array of integers
        valueSize - the exclusive end of the range of non-negative array values
        Throws:
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.NullPointerException - if ia == null
      • WrappedIntArray

        public WrappedIntArray​(IntList il)
        Constructs a new WrappedIntArray instance.
        Parameters:
        il - a list of integers
        Throws:
        java.lang.NullPointerException - if il == null
      • WrappedIntArray

        public WrappedIntArray​(IntList il,
                               int valueSize)
        Constructs a new WrappedIntArray instance.
        Parameters:
        il - a list of integers
        valueSize - the exclusive end of the range of non-negative array values
        Throws:
        java.lang.IllegalArgumentException - if (il[j] < 0 || il[j] > valueSize) for any index j satisfying (j >= 0 && j < il.length)
        java.lang.NullPointerException - if il == null
    • Method Detail

      • 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
      • 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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toArray

        public int[] toArray()
        Returns the list of integers.
        Returns:
        the list of integers
      • binarySearch

        public int binarySearch​(int key)
        Searches this for the specified value using the binary search algorithm. This list must be sorted (as by the java.util.Arrays.sort(int[]) method) prior to making this call. If it is not sorted, the results are undefined. If the list contains multiple elements with the specified value, there is no guarantee which one will be found.
        Parameters:
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or this.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
      • binarySearch

        public int binarySearch​(int fromIndex,
                                int toIndex,
                                int key)
        Searches the specified range of this for the specified value using the binary search algorithm. This range must be sorted (as by the java.util.Arrays.sort(int[]) method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.
        Parameters:
        fromIndex - the index of the first element (inclusive) to be searched
        toIndex - the index of the last element (exclusive) to be searched
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or this.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > this.size()