InMemorySetting

class InMemorySetting(clearExpiredKeysDuration: Duration? = null) : Settings

class provides an in memory version of the settings, mostly useful during unit tests.

Constructors

Link copied to clipboard
constructor(clearExpiredKeysDuration: Duration? = null)

Properties

Link copied to clipboard
open override val keys: Set<String>

Returns a Set containing all the keys present in this Settings.

Link copied to clipboard
open override var listener: Settings.Listener?
Link copied to clipboard
private var removeExpiredJob: Deferred<Unit>?
Link copied to clipboard
private val settings: MapSettings
Link copied to clipboard
open override val size: Int

Returns the number of key-value pairs present in this Settings.

Functions

Link copied to clipboard
open override fun cancelRemovingExpiredKeys()

In case you need to stop removing expired keys

Link copied to clipboard
open override fun clear()

Clears all values stored in this Settings instance.

Link copied to clipboard
inline operator fun Settings.contains(key: String): Boolean

Equivalent to Settings.hasKey

Link copied to clipboard
inline operator fun <T : Any> Settings.get(key: String): T?

Get the typed value stored at key if present, or return null if not. Throws IllegalArgumentException if T is not one of Int, Long, String, Float, Double, or Boolean.

inline operator fun Settings.get(key: String, defaultValue: Boolean): Boolean

Equivalent to Settings.getBoolean

inline operator fun Settings.get(key: String, defaultValue: Double): Double

Equivalent to Settings.getDouble

inline operator fun Settings.get(key: String, defaultValue: Float): Float

Equivalent to Settings.getFloat

inline operator fun Settings.get(key: String, defaultValue: Int): Int

Equivalent to Settings.getInt

inline operator fun Settings.get(key: String, defaultValue: Long): Long

Equivalent to Settings.getLong

inline operator fun Settings.get(key: String, defaultValue: String): String

Equivalent to Settings.getString

Link copied to clipboard
open override fun getBoolean(key: String, defaultValue: Boolean): Boolean

Returns the Boolean value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getBooleanFlow(key: String): Flow<Boolean?>

Returns a Flow Boolean value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getBooleanFlow(key: String, defaultValue: Boolean): Flow<Boolean>

Returns a Flow Boolean value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getBooleanOrNull(key: String): Boolean?

Returns the Boolean value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getDouble(key: String, defaultValue: Double): Double

Returns the Double value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getDoubleFlow(key: String): Flow<Double?>

Returns a Flow Double value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getDoubleFlow(key: String, defaultValue: Double): Flow<Double>

Returns a Flow Double value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getDoubleOrNull(key: String): Double?

Returns the Double value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getExpirableString(key: String): String?
open override fun getExpirableString(key: String, default: String?): String?
Link copied to clipboard
open override fun getFloat(key: String, defaultValue: Float): Float

Returns the Float value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getFloatFlow(key: String): Flow<Float?>

Returns a Flow Float value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getFloatFlow(key: String, defaultValue: Float): Flow<Float>

Returns a Flow Float value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getFloatOrNull(key: String): Float?

Returns the Float value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getInt(key: String, defaultValue: Int): Int

Returns the Int value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getIntFlow(key: String): Flow<Int?>

Returns a Flow Int value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getIntFlow(key: String, defaultValue: Int): Flow<Int>

Returns a Flow Int value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getIntOrNull(key: String): Int?

Returns the Int value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getLong(key: String, defaultValue: Long): Long

Returns the Long value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getLongFlow(key: String): Flow<Long?>

Returns a Flow Long value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getLongFlow(key: String, defaultValue: Long): Flow<Long>

Returns a Flow Long value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getLongOrNull(key: String): Long?

Returns the Long value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getString(key: String, defaultValue: String): String

Returns the String value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getStringFlow(key: String): Flow<String?>

Returns a Flow String value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

open override fun getStringFlow(key: String, defaultValue: String): Flow<String>

Returns a Flow String value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun getStringOrNull(key: String): String?

Returns the String value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
open override fun hasKey(key: String): Boolean

Returns true if there is a value stored at key, or false otherwise.

Link copied to clipboard
inline operator fun Settings.minusAssign(key: String)

Equivalent to Settings.remove

Link copied to clipboard
open override fun putBoolean(key: String, value: Boolean)

Stores the Boolean value at key.

Link copied to clipboard
open override fun putDouble(key: String, value: Double)

Stores the Double value at key.

Link copied to clipboard
open override fun putExpirableString(key: String, value: String, exp: Long)
open fun putExpirableString(key: String, value: String, exp: Duration)
Link copied to clipboard
open override fun putFloat(key: String, value: Float)

Stores the Float value at key.

Link copied to clipboard
open override fun putInt(key: String, value: Int)

Stores the Int value at key.

Link copied to clipboard
open override fun putLong(key: String, value: Long)

Stores the Long value at key.

Link copied to clipboard
open override fun putString(key: String, value: String)

Stores the String value at key.

Link copied to clipboard
open override fun remove(key: String)

Removes the value stored at key.

Link copied to clipboard
open override fun removeExpiredKeys()

Will loop all keys and remove the expired ones

Link copied to clipboard
inline operator fun <T : Any> Settings.set(key: String, value: T?)

Stores a typed value at key, or remove what's there if value is null. Throws IllegalArgumentException if T is not one of Int, Long, String, Float, Double, or Boolean.

inline operator fun Settings.set(key: String, value: Boolean)

Equivalent to Settings.putBoolean

inline operator fun Settings.set(key: String, value: Double)

Equivalent to Settings.putDouble

inline operator fun Settings.set(key: String, value: Float)

Equivalent to Settings.putFloat

inline operator fun Settings.set(key: String, value: Int)

Equivalent to Settings.putInt

inline operator fun Settings.set(key: String, value: Long)

Equivalent to Settings.putLong

inline operator fun Settings.set(key: String, value: Nothing?)

Equivalent to Settings.remove

inline operator fun Settings.set(key: String, value: String)

Equivalent to Settings.putString