Package ints

Class WrappedIntArray

java.lang.Object
ints.WrappedIntArray
All Implemented Interfaces:
IntArray

public final class WrappedIntArray extends 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.
    Constructs a new WrappedIntArray instance.
    WrappedIntArray(IntList il, int valueSize)
    Constructs a new WrappedIntArray instance.
    Constructs an WrappedIntrray object with the specified values.
  • Method Summary

    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
    Returns the number of elements in this IntArray.
    int[]
    Returns the list of integers.
     

    Methods inherited from class java.lang.Object

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

    • WrappedIntArray

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

      public WrappedIntArray(IntStream values)
      Constructs an WrappedIntrray object with the specified values.
      Parameters:
      values - a stream of integer values
      Throws:
      NullPointerException - if values == null
      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:
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • WrappedIntArray

      public WrappedIntArray(IntList il)
      Constructs a new WrappedIntArray instance.
      Parameters:
      il - a list of integers
      Throws:
      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:
      IllegalArgumentException - if (il[j] < 0 || il[j] > valueSize) for any index j satisfying (j >= 0 && j < il.length)
      NullPointerException - if il == null
  • Method Details

    • 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 String toString()
      Overrides:
      toString in class 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:
      IllegalArgumentException - if fromIndex > toIndex
      ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > this.size()