SavedStateReader


value public final class SavedStateReader


An inline class that encapsulates an opaque SavedState, and provides an API for reading the platform specific state.

See also
read

Summary

Public methods

final boolean

Checks if the SavedState contains the specified key.

final boolean

Checks if the two specified SavedState are deeply equal to one another.

final boolean

Retrieves a Boolean value associated with the specified key.

final boolean
getBooleanOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Boolean> defaultValue
)

Retrieves a Boolean value associated with the specified key, or a default value if the key doesn't exist.

final char

Retrieves a Char value associated with the specified key.

final char
getCharOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Character> defaultValue
)

Retrieves a Char value associated with the specified key, or a default value if the key doesn't exist.

final double

Retrieves a Double value associated with the specified key.

final double
getDoubleOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Double> defaultValue
)

Retrieves a Double value associated with the specified key, or a default value if the key doesn't exist.

final float

Retrieves a Float value associated with the specified key.

final float
getFloatOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Float> defaultValue
)

Retrieves a Float value associated with the specified key, or a default value if the key doesn't exist.

final int

Retrieves an Int value associated with the specified key.

final @NonNull List<@NonNull Integer>

Retrieves a List of elements of Int associated with the specified key.

final @NonNull List<@NonNull Integer>
getIntListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull Integer>> defaultValue
)

Retrieves a List of elements of Int associated with the specified key, or a default value if the key doesn't exist.

final int
getIntOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Integer> defaultValue
)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

final long

Retrieves an Long value associated with the specified key.

final long
getLongOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Long> defaultValue
)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

final @NonNull T
<T extends Parcelable> getParcelable(@NonNull String key)

Retrieves a Parcelable object associated with the specified key.

final @NonNull List<@NonNull T>

Retrieves a List of elements of Parcelable associated with the specified key.

final @NonNull List<@NonNull T>
<T extends Parcelable> getParcelableListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull T>> defaultValue
)

Retrieves a List of elements of Parcelable associated with the specified key, or a default value if the key doesn't exist.

final @NonNull T
<T extends Parcelable> getParcelableOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull T> defaultValue
)

Retrieves a Parcelable object associated with the specified key, or a default value if the key doesn't exist.

final @NonNull SavedState

Retrieves a SavedState object associated with the specified key.

final @NonNull SavedState
getSavedStateOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull SavedState> defaultValue
)

Retrieves a SavedState object associated with the specified key, or a default value if the key doesn't exist.

final @NonNull String

Retrieves a String value associated with the specified key.

final @NonNull List<@NonNull String>

Retrieves a List of elements of String associated with the specified key.

final @NonNull List<@NonNull String>
getStringListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull String>> defaultValue
)

Retrieves a List of elements of String associated with the specified key, or a default value if the key doesn't exist.

final @NonNull String
getStringOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull String> defaultValue
)

Retrieves a String value associated with the specified key, or a default value if the key doesn't exist.

final boolean

Checks if the SavedState is empty (contains no key-value pairs).

final boolean

Checks if the SavedState contains a null reference for the specified key.

final int

Returns the number of key-value pairs in the SavedState.

Extension functions

final @NonNull T
<T extends Object> SavedStateKt.write(
    @NonNull SavedStateReader receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block
)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Public methods

contains

Added in 1.3.0-alpha04
public final boolean contains(@NonNull String key)

Checks if the SavedState contains the specified key.

Parameters
@NonNull String key

The key to check for.

Returns
boolean

true if the SavedState contains the key, false otherwise.

contentDeepEquals

public final boolean contentDeepEquals(@NonNull SavedState other)

Checks if the two specified SavedState are deeply equal to one another.

Two SavedState are considered deeply equal if they have the same size, and elements at corresponding keys are deeply equal. That is, if two corresponding elements are nested SavedState, they are also compared deeply.

Parameters
@NonNull SavedState other

the object to compare deeply with this.

Returns
boolean

true if the two are deeply equal, false otherwise.

getBoolean

Added in 1.3.0-alpha04
public final boolean getBoolean(@NonNull String key)

Retrieves a Boolean value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
boolean

The Boolean value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getBooleanOrElse

Added in 1.3.0-alpha04
public final boolean getBooleanOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Boolean> defaultValue
)

Retrieves a Boolean value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Boolean> defaultValue

A function providing the default value if the key is not found.

Returns
boolean

The Boolean value associated with the key, or the default value if the key is not found.

getChar

Added in 1.3.0-alpha04
public final char getChar(@NonNull String key)

Retrieves a Char value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
char

The Char value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getCharOrElse

Added in 1.3.0-alpha04
public final char getCharOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Character> defaultValue
)

Retrieves a Char value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Character> defaultValue

A function providing the default value if the key is not found.

Returns
char

The Char value associated with the key, or the default value if the key is not found.

getDouble

Added in 1.3.0-alpha04
public final double getDouble(@NonNull String key)

Retrieves a Double value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
double

The Double value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getDoubleOrElse

Added in 1.3.0-alpha04
public final double getDoubleOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Double> defaultValue
)

Retrieves a Double value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Double> defaultValue

A function providing the default value if the key is not found.

Returns
double

The Double value associated with the key, or the default value if the key is not found.

getFloat

Added in 1.3.0-alpha04
public final float getFloat(@NonNull String key)

Retrieves a Float value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
float

The Float value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getFloatOrElse

Added in 1.3.0-alpha04
public final float getFloatOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Float> defaultValue
)

Retrieves a Float value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Float> defaultValue

A function providing the default value if the key is not found.

Returns
float

The Float value associated with the key, or the default value if the key is not found.

getInt

Added in 1.3.0-alpha04
public final int getInt(@NonNull String key)

Retrieves an Int value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
int

The Int value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getIntList

Added in 1.3.0-alpha04
public final @NonNull List<@NonNull IntegergetIntList(@NonNull String key)

Retrieves a List of elements of Int associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull List<@NonNull Integer>

The List of elements of Int associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getIntListOrElse

Added in 1.3.0-alpha04
public final @NonNull List<@NonNull IntegergetIntListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull Integer>> defaultValue
)

Retrieves a List of elements of Int associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull List<@NonNull Integer>> defaultValue

A function providing the default value if the key is not found or the retrieved value is not a list of Int.

Returns
@NonNull List<@NonNull Integer>

The list of elements of Int associated with the key, or the default value if the key is not found.

getIntOrElse

Added in 1.3.0-alpha04
public final int getIntOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Integer> defaultValue
)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Integer> defaultValue

A function providing the default value if the key is not found.

Returns
int

The Int value associated with the key, or the default value if the key is not found.

getLong

Added in 1.3.0-alpha04
public final long getLong(@NonNull String key)

Retrieves an Long value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
long

The Long value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getLongOrElse

Added in 1.3.0-alpha04
public final long getLongOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull Long> defaultValue
)

Retrieves an Int value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull Long> defaultValue

A function providing the default value if the key is not found.

Returns
long

The Int value associated with the key, or the default value if the key is not found.

getParcelable

public final @NonNull T <T extends Parcelable> getParcelable(@NonNull String key)

Retrieves a Parcelable object associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull T

The Parcelable object associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getParcelableList

public final @NonNull List<@NonNull T> <T extends Parcelable> getParcelableList(@NonNull String key)

Retrieves a List of elements of Parcelable associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull List<@NonNull T>

The List of elements of Parcelable associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getParcelableListOrElse

public final @NonNull List<@NonNull T> <T extends Parcelable> getParcelableListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull T>> defaultValue
)

Retrieves a List of elements of Parcelable associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull List<@NonNull T>> defaultValue

A function providing the default value if the key is not found or the retrieved value is not a list of Parcelable.

Returns
@NonNull List<@NonNull T>

The list of elements of Parcelable associated with the key, or the default value if the key is not found.

getParcelableOrElse

public final @NonNull T <T extends Parcelable> getParcelableOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull T> defaultValue
)

Retrieves a Parcelable object associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull T> defaultValue

A function providing the default Parcelable if the key is not found.

Returns
@NonNull T

The Parcelable object associated with the key, or the default value if the key is not found.

getSavedState

Added in 1.3.0-alpha04
public final @NonNull SavedState getSavedState(@NonNull String key)

Retrieves a SavedState object associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull SavedState

The SavedState object associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getSavedStateOrElse

public final @NonNull SavedState getSavedStateOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull SavedState> defaultValue
)

Retrieves a SavedState object associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull SavedState> defaultValue

A function providing the default SavedState if the key is not found.

Returns
@NonNull SavedState

The SavedState object associated with the key, or the default value if the key is not found.

getString

Added in 1.3.0-alpha04
public final @NonNull String getString(@NonNull String key)

Retrieves a String value associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull String

The String value associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getStringList

Added in 1.3.0-alpha04
public final @NonNull List<@NonNull StringgetStringList(@NonNull String key)

Retrieves a List of elements of String associated with the specified key. Throws an IllegalStateException if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

Returns
@NonNull List<@NonNull String>

The List of elements of String associated with the key.

Throws
kotlin.IllegalStateException

If the key is not found.

getStringListOrElse

Added in 1.3.0-alpha04
public final @NonNull List<@NonNull StringgetStringListOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull List<@NonNull String>> defaultValue
)

Retrieves a List of elements of String associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull List<@NonNull String>> defaultValue

A function providing the default value if the key is not found or the retrieved value is not a list of String.

Returns
@NonNull List<@NonNull String>

The list of elements of String associated with the key, or the default value if the key is not found.

getStringOrElse

Added in 1.3.0-alpha04
public final @NonNull String getStringOrElse(
    @NonNull String key,
    @NonNull Function0<@NonNull String> defaultValue
)

Retrieves a String value associated with the specified key, or a default value if the key doesn't exist.

Parameters
@NonNull String key

The key to retrieve the value for.

@NonNull Function0<@NonNull String> defaultValue

A function providing the default value if the key is not found.

Returns
@NonNull String

The String value associated with the key, or the default value if the key is not found.

isEmpty

Added in 1.3.0-alpha04
public final boolean isEmpty()

Checks if the SavedState is empty (contains no key-value pairs).

Returns
boolean

true if the SavedState is empty, false otherwise.

isNull

Added in 1.3.0-alpha04
public final boolean isNull(@NonNull String key)

Checks if the SavedState contains a null reference for the specified key.

Parameters
@NonNull String key

The key to check for.

Returns
boolean

true if the SavedState contains a null reference for the key, false otherwise.

size

Added in 1.3.0-alpha04
public final int size()

Returns the number of key-value pairs in the SavedState.

Returns
int

The size of the SavedState.

Extension functions

SavedStateKt.write

public final @NonNull T <T extends Object> SavedStateKt.write(
    @NonNull SavedStateReader receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block
)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Parameters
@ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block

A lambda function that performs write operations using the SavedStateWriter.

Returns
@NonNull T

The result of the lambda function's execution.