Package ints
Class IndexArray
- java.lang.Object
-
- ints.IndexArray
-
- All Implemented Interfaces:
IntArray
public class IndexArray extends java.lang.Object implements 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 aIndexArray
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
Constructors Constructor Description IndexArray(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
get(int index)
Returns the specified array element.IntArray
intArray()
Returns the wrappedIntArray
object.int
size()
Returns the number of elements in thisIntArray
.int
valueSize()
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
valueSize(IntArray ia)
Returns the minimum integer that is greater than all elements in the specified list of non-negative values.
-
-
-
Constructor Detail
-
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:
java.lang.NullPointerException
- ifIndexArray == null
-
IndexArray
public IndexArray(IntArray 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:
java.lang.NullPointerException
- ifIndexArray == null
-
-
Method Detail
-
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
public IntArray 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:
java.lang.IllegalArgumentException
- if any element of the specified array is negative
-
valueSize
public static int valueSize(IntArray ia)
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:
java.lang.IllegalArgumentException
- if any element of the specified array is negative
-
-