Config

interface Config : ItemContainer

Config containing items and associated values.

Config contains items, which can be loaded with addSpec. Config contains values, each of which is associated with corresponding item. Values can be loaded from source with withSource or from.

Config contains read-write access operations for item. Items in config is in one of three states:

  • Unset. Item has not associated value in this state. Use unset to change item to this state.

  • Unevaluated. Item is lazy and the associated value will be evaluated when accessing. Use lazySet to change item to this state.

  • Evaluated. Item has associated value which is evaluated. Use set to change item to this state.

Config is cascading. Config can fork from another config by adding a new layer on it. The forked config is called child config, and the original config is called parent config. A config without parent config is called root config. The new layer added by child config is called facade layer. Config with ancestor configs has multiple layers. All set operation is executed in facade layer of config. Descendant config inherits items and values in ancestor configs, and can override values for items in ancestor configs. Overridden values in config will affect itself and its descendant configs, without affecting its ancestor configs. Loading items in config will not affect its ancestor configs too. invoke can be used to create a root config, and withLayer can be used to create a child config from specified config.

All methods in Config is thread-safe.

Types

Companion
Link copied to clipboard
object Companion

Functions

addItem
Link copied to clipboard
abstract fun addItem(item: Item<*>, prefix: String = "")
Load item into facade layer with the specified prefix.
addSpec
Link copied to clipboard
abstract fun addSpec(spec: Spec)
Load items in specified config spec into facade layer.
afterLoad
Link copied to clipboard
abstract fun afterLoad(afterLoadFunction: (source: Source) -> Unit): Handler
Subscribe the update event after every load operation.
afterSet
Link copied to clipboard
abstract fun afterSet(afterSetFunction: (item: Item<*>, value: Any?) -> Unit): Handler
Subscribe the update event after every set operation.
at
Link copied to clipboard
abstract fun at(path: String): Config
Returns sub-config in the specified path.
beforeLoad
Link copied to clipboard
abstract fun beforeLoad(beforeLoadFunction: (source: Source) -> Unit): Handler
Subscribe the update event before every load operation.
beforeSet
Link copied to clipboard
abstract fun beforeSet(beforeSetFunction: (item: Item<*>, value: Any?) -> Unit): Handler
Subscribe the update event before every set operation.
clear
Link copied to clipboard
abstract fun clear()
Remove all values from the facade layer of this config.
clearAll
Link copied to clipboard
abstract fun clearAll()
Remove all values from all layers of this config.
contains
Link copied to clipboard
abstract operator fun contains(item: Item<*>): Boolean
Whether this item container contains specified item or not.
abstract operator fun contains(name: String): Boolean
Whether this item container contains item with specified name or not.
abstract operator fun contains(path: Path): Boolean
Whether this item container contains the specified path or not.
containsRequired
Link copied to clipboard
abstract fun containsRequired(): Boolean
Whether all required items have values or not.
disable
Link copied to clipboard
abstract fun disable(feature: Feature): Config
Disables the specified feature and returns this config.
enable
Link copied to clipboard
abstract fun enable(feature: Feature): Config
Enables the specified feature and returns this config.
forEach
Link copied to clipboard
open fun forEach(p0: Consumer<in Item<*>>)
from
Link copied to clipboard
open fun from(): DefaultLoaders
Returns default loaders for this config.
get
Link copied to clipboard
abstract operator fun <T> get(item: Item<T>): T
Get associated value with specified item.
abstract operator fun <T> get(name: String): T
Get associated value with specified item name.
getOrNull
Link copied to clipboard
abstract fun <T> getOrNull(item: Item<T>): T?
Returns associated value if specified item exists, null otherwise.
abstract fun <T> getOrNull(name: String): T?
Returns associated value if specified item name exists, null otherwise.
invoke
Link copied to clipboard
open operator fun <T> invoke(name: String): T
Get associated value with specified item name.
isEnabled
Link copied to clipboard
abstract fun isEnabled(feature: Feature): Boolean
Check whether the specified feature is enabled or not.
iterator
Link copied to clipboard
abstract operator override fun iterator(): Iterator<Item<*>>
Returns iterator of items in this item container.
lazySet
Link copied to clipboard
abstract fun <T> lazySet(item: Item<T>, thunk: (config: ItemContainer) -> T)
Associate item with specified thunk, which can be used to evaluate value for the item.
abstract fun <T> lazySet(name: String, thunk: (config: ItemContainer) -> T)
Find item with specified name, and associate item with specified thunk, which can be used to evaluate value for the item.
lock
Link copied to clipboard
abstract fun <T> lock(action: () -> T): T
Executes the given action after locking the facade layer of this config.
nameOf
Link copied to clipboard
abstract fun nameOf(item: Item<*>): String
Returns the qualified name of the specified item.
pathOf
Link copied to clipboard
open fun pathOf(item: Item<*>): Path
Returns the qualified path of the specified item.
plus
Link copied to clipboard
abstract operator fun plus(config: Config): Config
Returns a config overlapped by the specified facade config.
property
Link copied to clipboard
abstract fun <T> property(item: Item<T>): ReadWriteProperty<Any?, T>
Returns a property that can read/set associated value for specified item.
abstract fun <T> property(name: String): ReadWriteProperty<Any?, T>
Returns a property that can read/set associated value for item with specified name.
rawSet
Link copied to clipboard
abstract fun rawSet(item: Item<*>, value: Any?)
Associate item with specified value without type checking.
set
Link copied to clipboard
abstract operator fun <T> set(item: Item<T>, value: T)
Associate item with specified value.
abstract operator fun <T> set(name: String, value: T)
Find item with specified name, and associate it with specified value.
spliterator
Link copied to clipboard
open fun spliterator(): Spliterator<Item<*>>
toMap
Link copied to clipboard
abstract fun toMap(): Map<String, Any>
Returns a map in key-value format for this config.
unset
Link copied to clipboard
abstract fun unset(item: Item<*>)
Discard associated value of specified item.
abstract fun unset(name: String)
Discard associated value of item with specified name.
validateRequired
Link copied to clipboard
abstract fun validateRequired(): Config
Validate whether all required items have values or not.
withFallback
Link copied to clipboard
abstract fun withFallback(config: Config): Config
Returns a config backing by the specified fallback config.
withLayer
Link copied to clipboard
abstract fun withLayer(name: String = ""): Config
Returns a child config of this config with specified name.
withLoadTrigger
Link copied to clipboard
abstract fun withLoadTrigger(description: String, trigger: (config: Config, load: (source: Source) -> Unit) -> Unit): Config
Returns a child config containing values loaded by specified trigger.
withPrefix
Link copied to clipboard
abstract fun withPrefix(prefix: String): Config
Returns config with the specified additional prefix.
withSource
Link copied to clipboard
abstract fun withSource(source: Source): Config
Returns a child config containing values from specified source.

Properties

from
Link copied to clipboard
open val from: DefaultLoaders
Returns default loaders for this config.
items
Link copied to clipboard
open val items: List<Item<*>>
List of items in this item container.
itemWithNames
Link copied to clipboard
abstract val itemWithNames: List<Pair<Item<*>, String>>
List of items with the corresponding qualified names in this item container.
mapper
Link copied to clipboard
abstract val mapper: ObjectMapper
Returns ObjectMapper using to map from source to value in config.
name
Link copied to clipboard
abstract val name: String
Name of facade layer of config.
nameOfItems
Link copied to clipboard
open val nameOfItems: List<String>
List of qualified names of items in this item container.
parent
Link copied to clipboard
abstract val parent: Config?
Returns parent of this config, or null if this config is a root config.
sources
Link copied to clipboard
abstract val sources: List<Source>
List of sources from all layers of this config.
specs
Link copied to clipboard
abstract val specs: List<Spec>
List of config specs from all layers of this config.

Inheritors

BaseConfig
Link copied to clipboard

Extensions

cast
Link copied to clipboard
inline fun <T> Config.cast(): RequiredConfigProperty<T>
Returns a property that can read/set associated value casted from config.
lazy
Link copied to clipboard
inline fun <T> Config.lazy(prefix: String = "", name: String? = null, description: String = "", noinline thunk: (config: ItemContainer) -> T): LazyConfigProperty<T>
Returns a property that can read/set associated value for specified lazy item.
optional
Link copied to clipboard
inline fun <T> Config.optional(default: T, prefix: String = "", name: String? = null, description: String = ""): OptionalConfigProperty<T>
Returns a property that can read/set associated value for specified optional item.
required
Link copied to clipboard
inline fun <T> Config.required(prefix: String = "", name: String? = null, description: String = ""): RequiredConfigProperty<T>
Returns a property that can read/set associated value for specified required item.
toFlatMap
Link copied to clipboard
fun Config.toFlatMap(): Map<String, String>
Returns a map in flat format for this config.
toHierarchicalMap
Link copied to clipboard
fun Config.toHierarchicalMap(): Map<String, Any>
Returns a hierarchical map for this config.
toJson
Link copied to clipboard
val Config.toJson: Writer
Returns Writer for JSON source.
toProperties
Link copied to clipboard
val Config.toProperties: Writer
Returns writer for properties source.
toTree
Link copied to clipboard
fun Config.toTree(): TreeNode
Convert the config to a tree node.
toValue
Link copied to clipboard
inline fun <T> Config.toValue(): T
Returns a value casted from config.

Sources

jvm source
Link copied to clipboard