DataStore.Builder


public final class DataStore.Builder<T extends Object>


Builder for DataStore.

Summary

Public constructors

<T extends Object> Builder(
    @NonNull Storage<@NonNull T> storage,
    @NonNull CoroutineContext context
)

Public methods

final @NonNull DataStore.Builder<@NonNull T>

Adds DataMigrations to the DataStore.

final @NonNull DataStore<@NonNull T>

Validates the configuration and builds the Builder instance.

final @NonNull DataStore.Builder<@NonNull T>

Sets the CorruptionHandler for the DataStore.

final @NonNull DataStore.Builder<@NonNull T>

Sets the Tracer for Android.

Public constructors

Builder

public <T extends Object> Builder(
    @NonNull Storage<@NonNull T> storage,
    @NonNull CoroutineContext context
)

Public methods

addMigrations

public final @NonNull DataStore.Builder<@NonNull T> addMigrations(@NonNull List<@NonNull DataMigration<@NonNull T>> migrations)

Adds DataMigrations to the DataStore.

Migrations are run in the order they are added before any data is returned to the user.

Parameters
@NonNull List<@NonNull DataMigration<@NonNull T>> migrations

the list of migrations.

Returns
@NonNull DataStore.Builder<@NonNull T>

this Builder instance.

build

Added in 1.3.0-alpha07
public final @NonNull DataStore<@NonNull T> build()

Validates the configuration and builds the Builder instance.

Returns
@NonNull DataStore<@NonNull T>

a new DataStore instance.

setCorruptionHandler

Added in 1.3.0-alpha07
public final @NonNull DataStore.Builder<@NonNull T> setCorruptionHandler(@NonNull CorruptionHandler<@NonNull T> handler)

Sets the CorruptionHandler for the DataStore.

This handler is invoked if the Storage layer throws a CorruptionException. Defaults to ReThrowCorruptionHandler.

Parameters
@NonNull CorruptionHandler<@NonNull T> handler

the corruption handler.

Returns
@NonNull DataStore.Builder<@NonNull T>

this Builder instance.

setTracer

Added in 1.3.0-alpha07
public final @NonNull DataStore.Builder<@NonNull T> setTracer(@NonNull Tracer tracer)

Sets the Tracer for Android.

Parameters
@NonNull Tracer tracer

The Tracer to use.

Returns
@NonNull DataStore.Builder<@NonNull T>

this Builder instance.