Interface DataStorageBuilder

All Known Implementing Classes:
AbstractDataStorageBuilder, DoubleDataStorageBuilder, FloatDataStorageBuilder, IntDataStorageBuilder, LongDataStorageBuilder

public interface DataStorageBuilder
Interface for determining a suitable storage type for data of some expected size. The factory method pattern is used for creating the data storages.

The storage type can be different based on the size of the data. For example, it may be beneficial to store small amounts of data always in memory, for small overhead in access times, and to store larger objects on disk files, to avoid running out of memory.

Further, an implementing class may provide data storage objects that store data in disk files, for Java client applications, or e.g. in a relational database, for an EJB server environment where files are not allowed to be used.

Version:
1.5.1
Author:
Mikko Tommila
See Also:
  • Method Details

    • createDataStorage

      DataStorage createDataStorage(long size) throws ApfloatRuntimeException
      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.

      Parameters:
      size - The size of data to be stored in the storage, in bytes.
      Returns:
      An empty DataStorage object of an appropriate type for storing size bytes of data.
      Throws:
      ApfloatRuntimeException
    • createCachedDataStorage

      DataStorage createCachedDataStorage(long size) throws ApfloatRuntimeException
      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.

      Parameters:
      size - The size of data to be stored in the storage, in bytes.
      Returns:
      An empty DataStorage object of an appropriate type for storing size bytes of data, cached if possible.
      Throws:
      ApfloatRuntimeException
      Since:
      1.5.1
    • createDataStorage

      DataStorage createDataStorage(DataStorage dataStorage) throws ApfloatRuntimeException
      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 createCachedDataStorage(long) method, it can be created as well with the 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.

      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
      Since:
      1.5.1