|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object DPJRuntime.DPJArrayInt<region R>
R
- The region of a cell of this DPJArrayInt
public class DPJArrayInt<region R>
The DPJArray
class, specialized to int
.
The DPJArrayInt
class wraps and provides a "view" of an
ordinary Java array of int
. In addition to array-element
access, the DPJArrayInt
class supports the creation of a
subarray, which is a contiguous slice of the original array.
The subarray itself is a new DPJArrayInt
object. Both the
original DPJArrayInt
and the subarray wrap the same
underlying Java array.
A DPJArrayInt
stores a start position (indexed into the
underlying array) and a length. Accesses to the DPJArrayInt
are translated into accesses into the underlying array, offset by
the start position. They are bounds-checked against the length of
the DPJArrayInt
. For example:
// Create a Java array a of 10 int int[] a = new int[10]; // Wrap a in a DPJArrayInt DPJArrayInt A = new DPJArrayInt(a); // Create a subarray of A DPJArrayInt B = A.subarray(5,2); // Store value 1 into position 5 of a B.put(0,1); // Error: Out of bounds B.put(3,5);
Field Summary | |
---|---|
int |
length
The number of elements in the DPJArrayInt |
int |
start
The start index for indexing into the underlying array |
Constructor Summary | |
---|---|
DPJArrayInt(int length)
Creates a DPJArrayInt of the specified length, wrapping
a freshly created Java array with the same length. |
|
DPJArrayInt(int[]<R> elts)
Creates a DPJArrayInt that wraps the given Java array. |
Method Summary | |
---|---|
int |
get(int idx)
Returns the value stored at index idx of this DPJArrayInt . |
void |
put(int idx,
int val)
Replaces the value at index idx of this DPJArrayInt with value val . |
DPJArrayInt<R> |
subarray(int start,
int length)
Creates and returns a new DPJArrayInt starting at index
start with length length that wraps the same
underlying array as this DPJArrayInt . |
void |
swap(int i,
int j)
Swaps the values at indices i and j of this
DPJArrayInt . |
int[]<R> |
toArray()
Returns the underlying Java array for this DPJArrayInt . |
java.lang.String |
toString()
Returns a string representation of this DPJArrayInt . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final int start
public final int length
DPJArrayInt
Constructor Detail |
---|
public DPJArrayInt(int length) pure
DPJArrayInt
of the specified length, wrapping
a freshly created Java array with the same length.
length
- The length of the DPJArrayInt
public DPJArrayInt(int[]<R> elts) pure
DPJArrayInt
that wraps the given Java array.
elts
- The Java array to wrapMethod Detail |
---|
public int get(int idx) reads R
idx
of this DPJArrayInt
.
Throws ArrayIndexOutOfBoundsException
if idx
is outside the bounds of this DPJArrayInt
(even if it is
in bounds for the underlying array).
idx
- Index of value to returnreturn
- Value stored at idx
public void put(int idx, int val) writes R
idx
of this DPJArrayInt
with value val
.
Throws ArrayIndexOutOfBoundsException
if idx
is outside the bounds of this DPJArrayInt
(even if it is
in bounds for the underlying array).
idx
- Index of value to replaceval
- New valuepublic DPJArrayInt<R> subarray(int start, int length) pure
DPJArrayInt
starting at index
start
with length length
that wraps the same
underlying array as this DPJArrayInt
. Index i
of
the new DPJArrayInt
refers to the same cell of the
underlying array as index start+i
of this
.
Throws ArrayIndexOutOfBoundsException
if the
interval start,start+length-1]
is not in bounds for
this DPJArrayInt
.
start
- Start index for the subarraylength
- Length of the subarray
DPJArrayInt
defined by start
and length
public int[]<R> toArray() pure
DPJArrayInt
.
public java.lang.String toString() reads R
DPJArrayInt
.
toString
in class java.lang.Object
public void swap(int i, int j) writes R
i
and j
of this
DPJArrayInt
.
i
- First index to swapj
- Second index to swap
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |