Class AbstractDataStorageBuilder
- java.lang.Object
-
- org.apfloat.internal.AbstractDataStorageBuilder
-
- All Implemented Interfaces:
DataStorageBuilder
- Direct Known Subclasses:
DoubleDataStorageBuilder
,FloatDataStorageBuilder
,IntDataStorageBuilder
,LongDataStorageBuilder
public abstract class AbstractDataStorageBuilder extends java.lang.Object implements DataStorageBuilder
Abstract base class for a data storage creation strategy. Depending on the implementation-specific element size, the requested data length and threshold values configured in the currentApfloatContext
, different types of data storages are created.- Since:
- 1.7.0
- Version:
- 1.8.2
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDataStorageBuilder()
Subclass constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract DataStorage
createCachedDataStorage()
Create a cached data storage.DataStorage
createCachedDataStorage(long size)
Get a data storage that is cached in memory, if possible, for the requested size of data.DataStorage
createDataStorage(long size)
Get an appropriate type of data storage for the requested size of data.DataStorage
createDataStorage(DataStorage dataStorage)
Convert cached data storage to the appropriate normal data storage type.protected abstract DataStorage
createNonCachedDataStorage()
Create a non-cached data storage.protected abstract long
getMaxCachedSize()
Get the maximum cached data storage size.protected abstract boolean
isCached(DataStorage dataStorage)
Test if the data storage is of cached type.
-
-
-
Method Detail
-
createDataStorage
public DataStorage createDataStorage(long size) throws ApfloatRuntimeException
Description copied from interface:DataStorageBuilder
Get an appropriate type of data storage for the requested size of data.Note that the returned data storage object is not set to have the requested size, so the client should call the object's
DataStorage.setSize(long)
method before storing data to it.- Specified by:
createDataStorage
in interfaceDataStorageBuilder
- Parameters:
size
- The size of data to be stored in the storage, in bytes.- Returns:
- An empty
DataStorage
object of an appropriate type for storingsize
bytes of data. - Throws:
ApfloatRuntimeException
-
createCachedDataStorage
public DataStorage createCachedDataStorage(long size) throws ApfloatRuntimeException
Description copied from interface:DataStorageBuilder
Get a data storage that is cached in memory, if possible, for the requested size of data.Note that the returned data storage object is not set to have the requested size, so the client should call the object's
DataStorage.setSize(long)
method before storing data to it.- Specified by:
createCachedDataStorage
in interfaceDataStorageBuilder
- Parameters:
size
- The size of data to be stored in the storage, in bytes.- Returns:
- An empty
DataStorage
object of an appropriate type for storingsize
bytes of data, cached if possible. - Throws:
ApfloatRuntimeException
-
createDataStorage
public DataStorage createDataStorage(DataStorage dataStorage) throws ApfloatRuntimeException
Description copied from interface:DataStorageBuilder
Convert cached data storage to the appropriate normal data storage type.If the data storage already has the appropriate type for its size, the data storage may be returned unchanged. The argument data storage does not necessarily have to be created with the
DataStorageBuilder.createCachedDataStorage(long)
method, it can be created as well with theDataStorageBuilder.createDataStorage(long)
method.If the given data storage does not have the appropriate type for its size, then a new data storage of the appropriate type is created and the data is copied to it.
- Specified by:
createDataStorage
in interfaceDataStorageBuilder
- Parameters:
dataStorage
- The data storage to be converted, if necessary.- Returns:
- A
DataStorage
that can be the original data storage or a copy of it, with the appropriate type. - Throws:
ApfloatRuntimeException
-
getMaxCachedSize
protected abstract long getMaxCachedSize()
Get the maximum cached data storage size.- Returns:
- The maximum cached data storage size.
-
createCachedDataStorage
protected abstract DataStorage createCachedDataStorage() throws ApfloatRuntimeException
Create a cached data storage.- Returns:
- A new cached data storage.
- Throws:
ApfloatRuntimeException
-
createNonCachedDataStorage
protected abstract DataStorage createNonCachedDataStorage() throws ApfloatRuntimeException
Create a non-cached data storage.- Returns:
- A new non-cached data storage.
- Throws:
ApfloatRuntimeException
-
isCached
protected abstract boolean isCached(DataStorage dataStorage) throws ApfloatRuntimeException
Test if the data storage is of cached type.- Parameters:
dataStorage
- The data storage.- Returns:
- If the data storage is cached.
- Throws:
ApfloatRuntimeException
-
-