Package ints
Class WrappedIntArray
- java.lang.Object
-
- ints.WrappedIntArray
-
-
Constructor Summary
Constructors Constructor Description WrappedIntArray(int[] ia)
Constructs a newWrappedIntArray
instance.WrappedIntArray(int[] ia, int valueSize)
Constructs a newWrappedIntArray
instance.WrappedIntArray(IntList il)
Constructs a newWrappedIntArray
instance.WrappedIntArray(IntList il, int valueSize)
Constructs a newWrappedIntArray
instance.WrappedIntArray(java.util.stream.IntStream values)
Constructs anWrappedIntrray
object with the specified values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
binarySearch(int key)
Searchesthis
for the specified value using the binary search algorithm.int
binarySearch(int fromIndex, int toIndex, int key)
Searches the specified range ofthis
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 thisIntArray
.int[]
toArray()
Returns the list of integers.java.lang.String
toString()
-
-
-
Constructor Detail
-
WrappedIntArray
public WrappedIntArray(int[] ia)
Constructs a newWrappedIntArray
instance.- Parameters:
ia
- an array of integers- Throws:
java.lang.NullPointerException
- ifia == null
-
WrappedIntArray
public WrappedIntArray(java.util.stream.IntStream values)
Constructs anWrappedIntrray
object with the specified values.- Parameters:
values
- a stream of integer values- Throws:
java.lang.NullPointerException
- ifvalues == null
java.lang.IllegalStateException
- if the stream has previously been used
-
WrappedIntArray
public WrappedIntArray(int[] ia, int valueSize)
Constructs a newWrappedIntArray
instance.- 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 indexj
satisfying(j >= 0 && j < ia.length)
java.lang.NullPointerException
- ifia == null
-
WrappedIntArray
public WrappedIntArray(IntList il)
Constructs a newWrappedIntArray
instance.- Parameters:
il
- a list of integers- Throws:
java.lang.NullPointerException
- ifil == null
-
WrappedIntArray
public WrappedIntArray(IntList il, int valueSize)
Constructs a newWrappedIntArray
instance.- 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 indexj
satisfying(j >= 0 && j < il.length)
java.lang.NullPointerException
- ifil == null
-
-
Method Detail
-
size
public int size()
Description copied from interface:IntArray
Returns the number of elements in thisIntArray
.
-
get
public int get(int index)
Description copied from interface:IntArray
Returns the specified array element.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toArray
public int[] toArray()
Returns the list of integers.- Returns:
- the list of integers
-
binarySearch
public int binarySearch(int key)
Searchesthis
for 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>= 0
if and only if the key is found.
-
binarySearch
public int binarySearch(int fromIndex, int toIndex, int key)
Searches the specified range ofthis
for 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>= 0
if and only if the key is found. - Throws:
java.lang.IllegalArgumentException
- iffromIndex > toIndex
java.lang.ArrayIndexOutOfBoundsException
- iffromIndex < 0 || toIndex > this.size()
-
-