Package ints
Class IndexArray
java.lang.Object
ints.IndexArray
- All Implemented Interfaces:
IntArray
Class IndexArray
stores an array whose entries
are elements of a bounded set of non-negative integers along with an upper
bound. Both the stored array and upper bound are specified at the time of
object construction. It is the client code that constructs a
IndexArray
object's responsibility to ensure that the bound
specified at construction is correct. The contract for this class
is undefined if the bound is specified at object construction is incorrect.
It is recommended that the bound be the minimum integer that is greater
than all elements in the stored array, but not is not a requirement.
Instances of class IndexArray
are immutable.
-
Constructor Summary
ConstructorsConstructorDescriptionIndexArray
(int[] intArray, int valueSize) Constructs a newIndexArray
instance from the specified data.IndexArray
(IntArray intArray, int valueSize) Constructs a newIndexArray
instance from the specified data. -
Method Summary
Modifier and TypeMethodDescriptionint
get
(int index) Returns the specified array element.intArray()
Returns the wrappedIntArray
object.int
size()
Returns the number of elements in thisIntArray
.int
Returns the value size that was specified at construction.static int
valueSize
(int[] ia) Returns the minimum integer that is greater than all elements in the specified array of non-negative values.static int
Returns the minimum integer that is greater than all elements in the specified list of non-negative values.
-
Constructor Details
-
IndexArray
public IndexArray(int[] intArray, int valueSize) Constructs a newIndexArray
instance from the specified data. The contract for this constructor and class is unspecified if the sequence indices are not a subset of0, 1, ..., (valueSize - 1)
.- Parameters:
intArray
- an array with non-negative valuesvalueSize
- a value that is greater than all elements of the specified array- Throws:
NullPointerException
- ifIndexArray == null
-
IndexArray
Constructs a newIndexArray
instance from the specified data. The contract for this constructor and class is unspecified if the sequence indices are not a subset of0, 1, ..., (valueSize - 1)
.- Parameters:
intArray
- an array with non-negative valuesvalueSize
- a value that is greater than all elements of the specified array- Throws:
NullPointerException
- ifIndexArray == null
-
-
Method Details
-
get
public int get(int index) Description copied from interface:IntArray
Returns the specified array element. -
size
public int size()Description copied from interface:IntArray
Returns the number of elements in thisIntArray
. -
valueSize
public int valueSize()Returns the value size that was specified at construction.- Returns:
- the value size that was specified at construction
-
intArray
Returns the wrappedIntArray
object.- Returns:
- the wrapped
IntArray
object
-
valueSize
public static int valueSize(int[] ia) Returns the minimum integer that is greater than all elements in the specified array of non-negative values.- Parameters:
ia
- an array of non-negative values- Returns:
- the minimum integer that is greater than all elements in the specified array of non-negative values
- Throws:
IllegalArgumentException
- if any element of the specified array is negative
-
valueSize
Returns the minimum integer that is greater than all elements in the specified list of non-negative values.- Parameters:
ia
- an array of non-negative values- Returns:
- the minimum integer that is greater than all elements in the specified array of non-negative values
- Throws:
IllegalArgumentException
- if any element of the specified array is negative
-