DPJRuntime
Class DPJArrayByte<region R>

java.lang.Object
  extended by DPJRuntime.DPJArrayByte<region R>
Type Parameters:
R - The region of a cell of this DPJArrayByte

public class DPJArrayByte<region R>
extends java.lang.Object

The DPJArray class, specialized to byte.

The DPJArrayByte class wraps and provides a "view" of an ordinary Java array of byte. In addition to array-element access, the DPJArrayByte class supports the creation of a subarray, which is a contiguous slice of the original array. The subarray itself is a new DPJArrayByte object. Both the original DPJArrayByte and the subarray wrap the same underlying Java array.

A DPJArrayByte stores a start position (indexed into the underlying array) and a length. Accesses to the DPJArrayByte are translated into accesses into the underlying array, offset by the start position. They are bounds-checked against the length of the DPJArrayByte. For example:

 // Create a Java array a of 10 byte
 byte[] a = new byte[10];
 // Wrap a in a DPJArrayByte
 DPJArrayByte A = new DPJArrayByte(a);
 // Create a subarray of A
 DPJArrayByte 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 DPJArrayByte
 int start
          The start index for indexing into the underlying array
 
Constructor Summary
DPJArrayByte(byte[]<R> elts)
          Creates a DPJArrayByte that wraps the given Java array.
DPJArrayByte(int length)
          Creates a DPJArrayByte of the specified length, wrapping a freshly created Java array with the same length.
 
Method Summary
 byte get(int idx)
          Returns the value stored at index idx of this DPJArrayByte.
 void put(int idx, byte val)
          Replaces the value at index idx of this DPJArrayByte with value val.
 DPJArrayByte<R> subarray(int start, int length)
          Creates and returns a new DPJArrayByte starting at index start with length length that wraps the same underlying array as this DPJArrayByte.
 void swap(int i, int j)
          Swaps the values at indices i and j of this DPJArrayByte.
 byte[]<R> toArray()
          Returns the underlying Java array for this DPJArrayByte.
 java.lang.String toString()
          Returns a string representation of this DPJArrayByte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

start

public final int start
The start index for indexing into the underlying array


length

public final int length
The number of elements in the DPJArrayByte

Constructor Detail

DPJArrayByte

public DPJArrayByte(int length)
             pure
Creates a DPJArrayByte of the specified length, wrapping a freshly created Java array with the same length.

Parameters:
length - The length of the DPJArrayByte

DPJArrayByte

public DPJArrayByte(byte[]<R> elts)
             pure
Creates a DPJArrayByte that wraps the given Java array.

Parameters:
elts - The Java array to wrap
Method Detail

get

public byte get(int idx)
         reads  R
Returns the value stored at index idx of this DPJArrayByte.

Throws ArrayIndexOutOfBoundsException if idx is outside the bounds of this DPJArrayByte (even if it is in bounds for the underlying array).

Parameters:
idx - Index of value to return
return - Value stored at idx

put

public void put(int idx,
                byte val)
         writes R
Replaces the value at index idx of this DPJArrayByte with value val.

Throws ArrayIndexOutOfBoundsException if idx is outside the bounds of this DPJArrayByte (even if it is in bounds for the underlying array).

Parameters:
idx - Index of value to replace
val - New value

subarray

public DPJArrayByte<R> subarray(int start,
                                int length)
                         pure
Creates and returns a new DPJArrayByte starting at index start with length length that wraps the same underlying array as this DPJArrayByte. Index i of the new DPJArrayByte 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 DPJArrayByte.

Parameters:
start - Start index for the subarray
length - Length of the subarray
Returns:
Subarray of this DPJArrayByte defined by start and length

toArray

public byte[]<R> toArray()
                        pure
Returns the underlying Java array for this DPJArrayByte.

Returns:
The underlying Java array

toString

public java.lang.String toString()
                          reads  R
Returns a string representation of this DPJArrayByte.

Overrides:
toString in class java.lang.Object
Returns:
A string representation

swap

public void swap(int i,
                 int j)
          writes R
Swaps the values at indices i and j of this DPJArrayByte.

Parameters:
i - First index to swap
j - Second index to swap