Package ints
Class WrappedIntArray
- java.lang.Object
-
- ints.WrappedIntArray
-
-
Constructor Summary
Constructors Constructor Description WrappedIntArray(int[] ia)Constructs a newWrappedIntArrayinstance.WrappedIntArray(int[] ia, int valueSize)Constructs a newWrappedIntArrayinstance.WrappedIntArray(IntList il)Constructs a newWrappedIntArrayinstance.WrappedIntArray(IntList il, int valueSize)Constructs a newWrappedIntArrayinstance.WrappedIntArray(java.util.stream.IntStream values)Constructs anWrappedIntrrayobject with the specified values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbinarySearch(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.java.lang.StringtoString()
-
-
-
Constructor Detail
-
WrappedIntArray
public WrappedIntArray(int[] ia)
Constructs a newWrappedIntArrayinstance.- Parameters:
ia- an array of integers- Throws:
java.lang.NullPointerException- ifia == null
-
WrappedIntArray
public WrappedIntArray(java.util.stream.IntStream values)
Constructs anWrappedIntrrayobject with the specified values.- Parameters:
values- a stream of integer values- Throws:
java.lang.NullPointerException- ifvalues == nulljava.lang.IllegalStateException- 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:
java.lang.IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)java.lang.NullPointerException- ifia == null
-
WrappedIntArray
public WrappedIntArray(IntList il)
Constructs a newWrappedIntArrayinstance.- Parameters:
il- a list of integers- Throws:
java.lang.NullPointerException- ifil == null
-
WrappedIntArray
public WrappedIntArray(IntList il, int valueSize)
Constructs a newWrappedIntArrayinstance.- Parameters:
il- a list of integersvalueSize- the exclusive end of the range of non-negative array values- Throws:
java.lang.IllegalArgumentException- if(il[j] < 0 || il[j] > valueSize)for any indexjsatisfying(j >= 0 && j < il.length)java.lang.NullPointerException- ifil == null
-
-
Method Detail
-
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
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:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.ArrayIndexOutOfBoundsException- iffromIndex < 0 || toIndex > this.size()
-
-