|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object DPJRuntime.DPJArray<type T,region R>
T
- The type of an element of this DPJArray
R
- The region of a cell of this DPJArray
public class DPJArray<type T,region R>
The DPJArray
class wraps and provides a "view" of an
ordinary Java array. In addition to array-element access, the
DPJArray
class supports the creation of a subarray,
which is a contiguous slice of the original array. The subarray
itself is a new DPJArray
object. Both the original DPJArray
and the subarray wrap the same underlying Java array.
A DPJArray
stores a start position (indexed into the
underlying array) and a length. Accesses to the DPJArray
are translated into accesses into the underlying array, offset by
the start position. They are bounds-checked against the length of
the DPJArray
. For example:
// Create a Java array a of 10 Integers Integer[] a = new Integer[10]; // Wrap a in a DPJArray DPJArray<Integer> A = new DPJArray<Integer>(a) // Create a subarray of A DPJArray<Integer> 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 DPJArray |
int |
start
The start index for indexing into the underlying array |
Constructor Summary | |
---|---|
DPJArray(int length)
Creates a DPJArray of the specified length, wrapping a
freshly created Java array with the same length. |
|
DPJArray(T[]<R> elts)
Creates a DPJArray that wraps the given Java array. |
Method Summary | |
---|---|
T |
get(int idx)
Returns the value stored at index idx of this DPJArray . |
void |
put(int idx,
T val)
Replaces the value at index idx of this DPJArray with value val . |
DPJArray<T,R> |
subarray(int start,
int length)
Creates and returns a new DPJArray starting at index
start with length length that wraps the same
underlying array as this DPJArray . |
void |
swap(int i,
int j)
Swaps the values at indices i and j of this
DPJArray . |
T[]<R> |
toArray()
Returns the underlying Java array for this DPJArray . |
java.lang.String |
toString()
Returns a string representation of this DPJArray . |
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
DPJArray
Constructor Detail |
---|
public DPJArray(int length) pure
DPJArray
of the specified length, wrapping a
freshly created Java array with the same length.
length
- The length of the DPJArray
public DPJArray(T[]<R> elts) pure
DPJArray
that wraps the given Java array.
elts
- The Java array to wrapMethod Detail |
---|
public T get(int idx) reads R
idx
of this DPJArray
.
Throws ArrayIndexOutOfBoundsException
if idx
is outside the bounds of this DPJArray
(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, T val) writes R
idx
of this DPJArray
with value val
.
Throws ArrayIndexOutOfBoundsException
if idx
is outside the bounds of this DPJArray
(even if it is
in bounds for the underlying array).
idx
- Index of value to replaceval
- New valuepublic DPJArray<T,R> subarray(int start, int length) pure
DPJArray
starting at index
start
with length length
that wraps the same
underlying array as this DPJArray
. Index i
of
the new DPJArray
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 DPJArray
.
start
- Start index for the subarraylength
- Length of the subarray
DPJArray
defined by start
and length
public T[]<R> toArray() pure
DPJArray
.
public java.lang.String toString() reads R
DPJArray
.
toString
in class java.lang.Object
public void swap(int i, int j) writes R
i
and j
of this
DPJArray
.
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 |