Package ints
Class WrappedIntArray
java.lang.Object
ints.WrappedIntArray
- All Implemented Interfaces:
IntArray
Class WrappedIntArray represents an immutable
int[] array.
WrappedIntArray are immutable.-
Constructor Summary
ConstructorsConstructorDescriptionWrappedIntArray(int[] ia) Constructs a newWrappedIntArrayinstance.WrappedIntArray(int[] ia, int valueSize) Constructs a newWrappedIntArrayinstance.Constructs a newWrappedIntArrayinstance.WrappedIntArray(IntList il, int valueSize) Constructs a newWrappedIntArrayinstance.WrappedIntArray(IntStream values) Constructs anWrappedIntrrayobject with the specified values. -
Method Summary
Modifier and TypeMethodDescriptionintbinarySearch(int key) Searchesthisfor the specified value using the binary search algorithm.intbinarySearch(int fromIndex, int toIndex, int key) Searches the specified range ofthisfor the specified value using the binary search algorithm.intget(int index) Returns the specified array element.intsize()Returns the number of elements in thisIntArray.int[]toArray()Returns the list of integers.toString()
-
Constructor Details
-
WrappedIntArray
public WrappedIntArray(int[] ia) Constructs a newWrappedIntArrayinstance.- Parameters:
ia- an array of integers- Throws:
NullPointerException- ifia == null
-
WrappedIntArray
Constructs anWrappedIntrrayobject with the specified values.- Parameters:
values- a stream of integer values- Throws:
NullPointerException- ifvalues == nullIllegalStateException- if the stream has previously been used
-
WrappedIntArray
public WrappedIntArray(int[] ia, int valueSize) Constructs a newWrappedIntArrayinstance.- Parameters:
ia- an array of integersvalueSize- the exclusive end of the range of non-negative array values- Throws:
IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)NullPointerException- ifia == null
-
WrappedIntArray
Constructs a newWrappedIntArrayinstance.- Parameters:
il- a list of integers- Throws:
NullPointerException- ifil == null
-
WrappedIntArray
Constructs a newWrappedIntArrayinstance.- Parameters:
il- a list of integersvalueSize- the exclusive end of the range of non-negative array values- Throws:
IllegalArgumentException- if(il[j] < 0 || il[j] > valueSize)for any indexjsatisfying(j >= 0 && j < il.length)NullPointerException- ifil == null
-
-
Method Details
-
size
public int size()Description copied from interface:IntArrayReturns the number of elements in thisIntArray. -
get
public int get(int index) Description copied from interface:IntArrayReturns the specified array element. -
toString
-
toArray
public int[] toArray()Returns the list of integers.- Returns:
- the list of integers
-
binarySearch
public int binarySearch(int key) Searchesthisfor the specified value using the binary search algorithm. This list must be sorted (as by thejava.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, orthis.size()if all elements in the list are less than the specified key. Note that this guarantees that the return value will be>= 0if and only if the key is found.
-
binarySearch
public int binarySearch(int fromIndex, int toIndex, int key) Searches the specified range ofthisfor the specified value using the binary search algorithm. This range must be sorted (as by thejava.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 searchedtoIndex- the index of the last element (exclusive) to be searchedkey- 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, orthis.size()if all elements in the list are less than the specified key. Note that this guarantees that the return value will be>= 0if and only if the key is found. - Throws:
IllegalArgumentException- iffromIndex > toIndexArrayIndexOutOfBoundsException- iffromIndex < 0 || toIndex > this.size()
-