Compound

class Compound

A compound is a key-value storage intended for serialization via Cbf.

After deserialization, a Compound contains only binary data of values of unknown types (and the keys under which they're stored), which is then lazily deserialized to the requested type when accessed via get. Conversely, the type information for serialization is remembered during set.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

A set of all keys in this compound.

Functions

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

Checks whether this compound has an entry under key.

Link copied to clipboard
fun copy(): Compound

Creates a deep copy of this compound, copying all deserialized values using Cbf.copy.

fun copy(copyFunc: (KType, Any) -> Any): Compound

Creates a deep copy of this compound, copying all deserialized values using copyFunc.

Link copied to clipboard
@JvmName(name = "entry1")
inline fun <T : Any> entry(key: String, noinline defaultValue: () -> T? = { null }): MutableProvider<T?>

Creates a MutableProvider of the type T that is linked to the value of this compound under key. If this compound does not have an entry under key, defaultValue is used to create it lazily. If there is already an entry provider for key that matches T, defaultValue will be ignored and the existing provider will be returned.

@JvmName(name = "entry0")
inline fun <T : Any> entry(key: String, noinline defaultValue: () -> T): MutableProvider<T>

Creates a MutableProvider of the non-null type T that is linked to the value of this compound under key. If this compound does not have an entry under key, defaultValue is used to create it lazily. If there is already an entry provider for key that matches T, defaultValue will be ignored and the existing provider will be returned.

@JvmName(name = "entry1")
fun <T> entry(type: KType, key: String, defaultValue: () -> T): MutableProvider<T>

Creates a MutableProvider of type that is linked to the value of this compound under key. If this compound does not have an entry under key, defaultValue is used to create it lazily. If there is already an entry provider for key that matches type, defaultValue will be ignored and the existing provider will be returned.

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

Gets the value under key as T or null if it doesn't exist.

fun <T : Any> get(type: KType, key: String): T?

Gets the value under key as type or null if it doesn't exist.

Link copied to clipboard
inline fun <T : Any> getOrPut(key: String, noinline defaultValue: () -> T): T

Gets the value under key as T or puts and returns the value generated by defaultValue if it doesn't exist.

fun <T : Any> getOrPut(type: KType, key: String, defaultValue: () -> T): T

Gets the value under key as type or puts and returns the value generated by defaultValue if it doesn't exist.

Link copied to clipboard

Checks whether this compound is empty.

Link copied to clipboard

Checks whether this compound is not empty.

Link copied to clipboard
fun putAll(other: Compound)

Puts all entries from other into this compound.

Link copied to clipboard
fun rename(old: String, new: String)

Renames an entry from old to new. If there already is an entry under new, it will be overwritten.

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

Puts value into the compound under key, remembering T for serialization.

fun <T> set(type: KType, key: String, value: T)

Puts value into the compound under key, remembering type for serialization.

Link copied to clipboard

Creates a shallow copy of this compound, not copying any values.

Link copied to clipboard
open override fun toString(): String