public abstract class ArrayAccess extends Object implements Serializable
ArrayAccess
class simulates a C
language pointer.
With one ArrayAccess
object you can point to a location within an
array. You can easily add or subtract a value to this "pointer", thus
essentially emulating C
pointer arithmetic. An ArrayAccess
provides an array, the starting index within that array and the length of
accessible data within the array, all in one convenient package.
Just like pointers in the C
language, ArrayAccess
objects are inherently unsafe and must be used cautiously. It is the
responsibility of the user of an ArrayAccess
object to make sure
that he doesn't access the provided array outside the allowed range. The
ArrayAccess
object itself does nothing to enforce this, except
of course the mandatory bounds check of Java, which can throw an
ArrayIndexOutOfBoundsException
.
Modifier | Constructor and Description |
---|---|
protected |
ArrayAccess(int offset,
int length)
Create an array access.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Close this array access and commit any changes to the
underlying data storage if applicable.
|
abstract Object |
getData()
Returns the array of this array access.
|
double[] |
getDoubleData()
Returns the array of this array access as a
double[] . |
float[] |
getFloatData()
Returns the array of this array access as a
float[] . |
int[] |
getIntData()
Returns the array of this array access as an
int[] . |
int |
getLength()
Returns the length of the access segment within the backing array.
|
long[] |
getLongData()
Returns the array of this array access as a
long[] . |
int |
getOffset()
Returns the offset of the access segment within the backing array.
|
abstract ArrayAccess |
subsequence(int offset,
int length)
Create a sub-sequence view of this array access.
|
protected ArrayAccess(int offset, int length)
offset
- The offset of the access segment within the array.length
- The access segment.public abstract ArrayAccess subsequence(int offset, int length)
Note that the changes done to the sub-sequence array
are not necessarily committed to the underlying data
storage when the sub-sequence is closed (with close()
),
but only when the "base" ArrayAccess
is closed.
offset
- The sub-sequence starting offset within this ArrayAccess.length
- The sub-sequence length.public abstract Object getData() throws ApfloatRuntimeException
ApfloatRuntimeException
public int[] getIntData() throws UnsupportedOperationException, ApfloatRuntimeException
int[]
.UnsupportedOperationException
- In case the backing array can't be presented as int[]
.ApfloatRuntimeException
public long[] getLongData() throws UnsupportedOperationException, ApfloatRuntimeException
long[]
.UnsupportedOperationException
- In case the backing array can't be presented as long[]
.ApfloatRuntimeException
public float[] getFloatData() throws UnsupportedOperationException, ApfloatRuntimeException
float[]
.UnsupportedOperationException
- In case the backing array can't be presented as float[]
.ApfloatRuntimeException
public double[] getDoubleData() throws UnsupportedOperationException, ApfloatRuntimeException
double[]
.UnsupportedOperationException
- In case the backing array can't be presented as double[]
.ApfloatRuntimeException
public int getOffset()
public int getLength()
public abstract void close() throws ApfloatRuntimeException
If the ArrayAccess
was obtained in write
mode, the changes are saved to the data storage. Note
that even if the ArrayAccess
was obtained
for reading only, any changes made to the array data
may still be committed to the data storage.
Note that changes done to a sub-sequence array
are not necessarily committed to the underlying data
storage when the sub-sequence is closed,
but only when the "base" ArrayAccess
is closed.
ApfloatRuntimeException
Copyright © 2018. All rights reserved.