public abstract class DataStorage extends Object implements Serializable
Initially when a data storage is created, it is mutable
(it can be modified). After the contents have been properly
set, the user should call setReadOnly()
to set the
storage to be immutable. After this the data storage can be
safely shared between different users.
Access to DataStorage
objects is generally not internally synchronized.
Accessing multiple non-overlapping parts of the storage concurrently with the
getArray(int,long,int)
, getArray(int,int,int,int)
or getTransposedArray(int,int,int,int)
method and with
iterators over non-overlapping parts is permitted. Invoking
other methods must generally be externally synchronized.
Modifier and Type | Class and Description |
---|---|
protected class |
DataStorage.AbstractIterator
Abstract base class for iterators iterating through this
DataStorage . |
static class |
DataStorage.Iterator
Iterator for iterating through elements of the data storage.
|
Modifier and Type | Field and Description |
---|---|
static int |
READ
Read access mode specifier.
|
static int |
READ_WRITE
Read-write access mode specifier.
|
static int |
WRITE
Write access mode specifier.
|
Modifier | Constructor and Description |
---|---|
protected |
DataStorage()
Default constructor.
|
protected |
DataStorage(DataStorage dataStorage,
long offset,
long length)
Subsequence constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
copyFrom(DataStorage dataStorage)
Copies all data from another data storage to this data storage.
|
void |
copyFrom(DataStorage dataStorage,
long size)
Copies the specified number of elements from another data storage to this data storage.
|
ArrayAccess |
getArray(int mode,
int startColumn,
int columns,
int rows)
Maps a block of data to a memory array when the data is treated as a matrix.
|
ArrayAccess |
getArray(int mode,
long offset,
int length)
Gets an array access to the data of this data storage when
the data is treated as a linear block.
|
protected long |
getOffset()
Return the sub-sequence offset.
|
long |
getSize()
Return the size of the data storage, or the length of this sub-sequence
if this data storage is a sub-sequence.
|
ArrayAccess |
getTransposedArray(int mode,
int startColumn,
int columns,
int rows)
Maps a transposed block of data to a memory array when the data is treated as a matrix.
|
protected abstract void |
implCopyFrom(DataStorage dataStorage,
long size)
Copies the specified number of elements from another data storage to this data storage.
|
protected abstract ArrayAccess |
implGetArray(int mode,
int startColumn,
int columns,
int rows)
Maps a block of data to a memory array when the data is treated as a matrix.
|
protected abstract ArrayAccess |
implGetArray(int mode,
long offset,
int length)
Gets an array access to the data of this data storage when it is treated as a linear block.
|
protected abstract long |
implGetSize()
Return the size of the whole data storage, not including sub-sequence settings.
|
protected abstract ArrayAccess |
implGetTransposedArray(int mode,
int startColumn,
int columns,
int rows)
Maps a transposed block of data to a memory array when the data is treated as a matrix.
|
protected abstract void |
implSetSize(long size)
Sets the size of the data storage.
|
protected abstract DataStorage |
implSubsequence(long offset,
long length)
Implementation of getting a subsequence of this data storage.
|
abstract boolean |
isCached()
Is this object cached in memory.
|
boolean |
isReadOnly()
Returns the read-only state of this data storage.
|
boolean |
isSubsequenced()
Is this object a subsequence of some other object, or do subsequences of this object exist.
|
abstract DataStorage.Iterator |
iterator(int mode,
long startPosition,
long endPosition)
Constructs a new iterator.
|
void |
setReadOnly()
Sets this data storage as read-only.
|
void |
setSize(long size)
Sets the size of the data storage.
|
DataStorage |
subsequence(long offset,
long length)
Get a subsequence of this data storage.
|
public static final int READ
public static final int WRITE
public static final int READ_WRITE
READ | WRITE
.protected DataStorage()
DataStorage
.protected DataStorage(DataStorage dataStorage, long offset, long length)
dataStorage
- The originating data storage.offset
- The subsequence starting position.length
- The subsequence length.public final DataStorage subsequence(long offset, long length) throws IllegalArgumentException, ApfloatRuntimeException
offset
- The subsequence starting position.length
- The subsequence length.IllegalArgumentException
- If the requested subsequence is out of range.ApfloatRuntimeException
protected abstract DataStorage implSubsequence(long offset, long length) throws ApfloatRuntimeException
offset
- The subsequence starting position.length
- The subsequence length.ApfloatRuntimeException
public final void copyFrom(DataStorage dataStorage) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
dataStorage
- The data storage where the data should be copied from.IllegalArgumentException
- If the origin data source has a size of zero.IllegalStateException
- If this data storage is read-only or has subsequences.ApfloatRuntimeException
public final void copyFrom(DataStorage dataStorage, long size) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
dataStorage
- The data storage where the data should be copied from.size
- The number of elements to be copied.IllegalArgumentException
- If the size is invalid or zero.IllegalStateException
- If this data storage is read-only or has subsequences.ApfloatRuntimeException
protected abstract void implCopyFrom(DataStorage dataStorage, long size) throws ApfloatRuntimeException
dataStorage
- The data storage where the data should be copied from.size
- The number of elements to be copied.ApfloatRuntimeException
public final long getSize() throws ApfloatRuntimeException
ApfloatRuntimeException
protected abstract long implGetSize() throws ApfloatRuntimeException
ApfloatRuntimeException
public final void setSize(long size) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
size
- The size of the data storage.IllegalArgumentException
- If the size is invalid or zero.IllegalStateException
- If this data storage is read-only or has subsequences.ApfloatRuntimeException
protected abstract void implSetSize(long size) throws ApfloatRuntimeException
size
- The size of the data storage.ApfloatRuntimeException
public final boolean isReadOnly()
true
if this data storage is read-only, otherwise false
.public final void setReadOnly() throws ApfloatRuntimeException
ApfloatRuntimeException
public final ArrayAccess getArray(int mode, long offset, int length) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
mode
- Access mode for the array access: READ
, WRITE
or both.offset
- Starting position of the array access in the data storage.length
- Number of accessible elements in the array access.IllegalArgumentException
- If the offset or length are out of bounds of the data storage.IllegalStateException
- If write access is requested for a read-only data storage.ApfloatRuntimeException
protected abstract ArrayAccess implGetArray(int mode, long offset, int length) throws ApfloatRuntimeException
mode
- Access mode for the array access: READ
, WRITE
or both.offset
- Starting position of the array access in the data storage.length
- Number of accessible elements in the array access.ApfloatRuntimeException
public final ArrayAccess getArray(int mode, int startColumn, int columns, int rows) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
← startColumn →
|
← columns →
|
↑
|
← n2 →
|
mode
- Whether the array is prepared for reading, writing or both. The value should be READ
, WRITE
or a combination of these.startColumn
- The starting column where data is read.columns
- The number of columns of data to read.rows
- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.columns
x rows
containing the data.IllegalArgumentException
- If the requested area is out of bounds of the data storage.IllegalStateException
- If write access is requested for a read-only data storage.ApfloatRuntimeException
protected abstract ArrayAccess implGetArray(int mode, int startColumn, int columns, int rows) throws ApfloatRuntimeException
mode
- Whether the array is prepared for reading, writing or both. The value should be READ
, WRITE
or a combination of these.startColumn
- The starting column where data is read.columns
- The number of columns of data to read.rows
- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.columns
x rows
containing the data.ApfloatRuntimeException
public final ArrayAccess getTransposedArray(int mode, int startColumn, int columns, int rows) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
columns
is the value b
:
← startColumn →
|
A
|
↑
|
B
|
||
C
|
||
D
|
||
← b →
|
||
← n2 →
|
A
|
↑
|
B
|
|
C
|
|
D
|
|
← n1 →
|
A
|
B
|
C
|
D
|
↑
|
← n1 →
|
mode
- Whether the array is prepared for reading, writing or both. The value should be READ
, WRITE
or a combination of these.startColumn
- The starting column where data is read.columns
- The number of columns of data to read.rows
- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.columns
x rows
containing the transposed data.IllegalArgumentException
- If the requested area is out of bounds of the data storage.IllegalStateException
- If write access is requested for a read-only data storage.ApfloatRuntimeException
protected abstract ArrayAccess implGetTransposedArray(int mode, int startColumn, int columns, int rows) throws ApfloatRuntimeException
mode
- Whether the array is prepared for reading, writing or both. The value should be READ
, WRITE
or a combination of these.startColumn
- The starting column where data is read.columns
- The number of columns of data to read.rows
- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.columns
x rows
containing the transposed data.ApfloatRuntimeException
public abstract DataStorage.Iterator iterator(int mode, long startPosition, long endPosition) throws IllegalArgumentException, IllegalStateException, ApfloatRuntimeException
startPosition
is less than or greater than endPosition
, correspondingly.mode
- Access mode for iterator: READ
, WRITE
or both.startPosition
- Starting position of iterator in the data set. For reverse access, the first element in the iterator is startPosition - 1
.endPosition
- End position of iterator in the data set. For forward access, the last accessible element in the iterator is endPosition - 1
.IllegalArgumentException
- If the requested area is out of bounds of the data storage.IllegalStateException
- If write access is requested for a read-only data storage.ApfloatRuntimeException
public final boolean isSubsequenced()
true
if this object is a subsequence of some other object, or if subsequences of this object exist, false
otherwise.public abstract boolean isCached()
true
if this object is cached in memory, false
if not.protected final long getOffset()
Copyright © 2019. All rights reserved.