Class ArrayAccess
- All Implemented Interfaces:
Serializable
,AutoCloseable
- Direct Known Subclasses:
DoubleMemoryArrayAccess
,FloatMemoryArrayAccess
,IntMemoryArrayAccess
,LongMemoryArrayAccess
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
.
- Version:
- 1.9.0
- Author:
- Mikko Tommila
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ArrayAccess
(int offset, int length) Create an array access. -
Method Summary
Modifier and TypeMethodDescriptionabstract 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[]
Returns the array of this array access as adouble[]
.float[]
Returns the array of this array access as afloat[]
.int[]
Returns the array of this array access as anint[]
.int
Returns the length of the access segment within the backing array.long[]
Returns the array of this array access as along[]
.int
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.
-
Constructor Details
-
ArrayAccess
protected ArrayAccess(int offset, int length) Create an array access.- Parameters:
offset
- The offset of the access segment within the array.length
- The access segment.
-
-
Method Details
-
subsequence
Create a sub-sequence view of this array access.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.- Parameters:
offset
- The sub-sequence starting offset within this ArrayAccess.length
- The sub-sequence length.- Returns:
- The sub-sequence array access.
-
getData
Returns the array of this array access. This is an array of a primitive type, depending on the implementation class.- Returns:
- The backing array of this array access.
- Throws:
ApfloatRuntimeException
-
getIntData
Returns the array of this array access as anint[]
.- Returns:
- The backing array of this array access.
- Throws:
UnsupportedOperationException
- In case the backing array can't be presented asint[]
.ApfloatRuntimeException
-
getLongData
Returns the array of this array access as along[]
.- Returns:
- The backing array of this array access.
- Throws:
UnsupportedOperationException
- In case the backing array can't be presented aslong[]
.ApfloatRuntimeException
-
getFloatData
Returns the array of this array access as afloat[]
.- Returns:
- The backing array of this array access.
- Throws:
UnsupportedOperationException
- In case the backing array can't be presented asfloat[]
.ApfloatRuntimeException
-
getDoubleData
Returns the array of this array access as adouble[]
.- Returns:
- The backing array of this array access.
- Throws:
UnsupportedOperationException
- In case the backing array can't be presented asdouble[]
.ApfloatRuntimeException
-
getOffset
public int getOffset()Returns the offset of the access segment within the backing array.- Returns:
- The starting index within the backing array that is allowed to be accessed.
-
getLength
public int getLength()Returns the length of the access segment within the backing array.- Returns:
- The number of elements within the backing array that is allowed to be accessed.
-
close
Close this array access and commit any changes to the underlying data storage if applicable.If the
ArrayAccess
was obtained in write mode, the changes are saved to the data storage. Note that even if theArrayAccess
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.- Specified by:
close
in interfaceAutoCloseable
- Throws:
ApfloatRuntimeException
-