Package ints
Class IndexArray
- java.lang.Object
-
- ints.IndexArray
-
- All Implemented Interfaces:
IntArray
public class IndexArray extends java.lang.Object implements IntArray
Class
IndexArraystores 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 aIndexArrayobject'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
IndexArrayare immutable.
-
-
Constructor Summary
Constructors Constructor Description IndexArray(int[] intArray, int valueSize)Constructs a newIndexArrayinstance from the specified data.IndexArray(IntArray intArray, int valueSize)Constructs a newIndexArrayinstance from the specified data.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intget(int index)Returns the specified array element.IntArrayintArray()Returns the wrappedIntArrayobject.intsize()Returns the number of elements in thisIntArray.intvalueSize()Returns the value size that was specified at construction.static intvalueSize(int[] ia)Returns the minimum integer that is greater than all elements in the specified array of non-negative values.static intvalueSize(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 newIndexArrayinstance 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 newIndexArrayinstance 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:IntArrayReturns the specified array element.
-
size
public int size()
Description copied from interface:IntArrayReturns 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 wrappedIntArrayobject.- Returns:
- the wrapped
IntArrayobject
-
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
-
-