GuavaDataStore.Builder


public final class GuavaDataStore.Builder<T extends Object>


Builder class for a GuavaDataStore that works on a single process.

Summary

Public constructors

<T extends Object> Builder(
    @NonNull Serializer<@NonNull T> serializer,
    @NonNull Callable<@NonNull File> produceFile
)
<T extends Object> Builder(
    @NonNull Context context,
    @NonNull String fileName,
    @NonNull Serializer<@NonNull T> serializer
)

Create a GuavaDataStoreBuilder with the Context and name from which to derive the DataStore file.

Public methods

final @NonNull GuavaDataStore.Builder<@NonNull T>

Add a DataMigration to the Datastore.

final @NonNull GuavaDataStore<@NonNull T>

Build the DataStore.

final @NonNull GuavaDataStore.Builder<@NonNull T>

Sets the corruption handler to install into the DataStore.

final @NonNull GuavaDataStore.Builder<@NonNull T>

Sets the Executor used by the DataStore.

Public constructors

Builder

public <T extends Object> Builder(
    @NonNull Serializer<@NonNull T> serializer,
    @NonNull Callable<@NonNull File> produceFile
)

Builder

public <T extends Object> Builder(
    @NonNull Context context,
    @NonNull String fileName,
    @NonNull Serializer<@NonNull T> serializer
)

Create a GuavaDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by File(this.filesDir, "datastore/$fileName"). The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

Either produceFile or context & name must be set, but not both. This is enforced by the two constructors.

Parameters
@NonNull Context context

the Context from which we retrieve files directory.

@NonNull String fileName

the filename relative to Context.applicationContext.filesDir that DataStore acts on. The File is obtained from dataStoreFile. It is created in the "/datastore" subdirectory.

@NonNull Serializer<@NonNull T> serializer

the Serializer for the type that this DataStore acts on.

Public methods

addDataMigration

Added in 1.2.0-alpha01
public final @NonNull GuavaDataStore.Builder<@NonNull T> addDataMigration(@NonNull DataMigration<@NonNull T> dataMigration)

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

Parameters
@NonNull DataMigration<@NonNull T> dataMigration

the migration to add

build

Added in 1.2.0-alpha01
public final @NonNull GuavaDataStore<@NonNull T> build()

Build the DataStore.

Returns
@NonNull GuavaDataStore<@NonNull T>

the DataStore with the provided parameters

setCorruptionHandler

Added in 1.2.0-alpha01
public final @NonNull GuavaDataStore.Builder<@NonNull T> setCorruptionHandler(
    @NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler
)

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

Parameters
@NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler

the handler to invoke when there is a file corruption

setExecutor

Added in 1.2.0-alpha01
public final @NonNull GuavaDataStore.Builder<@NonNull T> setExecutor(@NonNull Executor executor)

Sets the Executor used by the DataStore.

This parameter is optional and defaults to Dispatchers.IO.

Parameters
@NonNull Executor executor

the executor to be used by DataStore