ConfigWrapper

interface ConfigWrapper

An abstraction for an underlying configuration store. Decouples config delegates from the underlying config framework.

Functions

Link copied to clipboard
abstract fun addDefault(path: String, value: Any)

Adds a default value to be used in absence of a value provided by the client.

Link copied to clipboard
abstract fun getBoolean(path: String): Boolean

Gets the specified Boolean configuration value. If the value is not set or not a valid boolean, the default value provided by addDefault is returned.

Link copied to clipboard
abstract fun getBooleanList(path: String): List<Boolean>

Gets the specified List of Boolean configuration value. If the value is not set or not a valid boolean list, the default value provided by addDefault is returned. A key present without a value reads as an empty list. Elements that cannot be converted are skipped with a warning.

Link copied to clipboard
abstract fun getComments(path: String): List<String>

Returns the comment lines of the key at path without the leading # , or an empty list if none. The file header is not part of the first key's comments.

Link copied to clipboard
abstract fun getDouble(path: String): Double

Gets the specified Double configuration value. If the value is not set or not a valid double, the default value provided by addDefault is returned.

Link copied to clipboard
abstract fun getDoubleList(path: String): List<Double>

Gets the specified List of Double configuration value. If the value is not set or not a valid double list, the default value provided by addDefault is returned. A key present without a value reads as an empty list. Elements that cannot be converted are skipped with a warning.

Link copied to clipboard
abstract fun getInt(path: String): Int

Gets the specified Int configuration value. If the value is not set or not a valid integer, the default value provided by addDefault is returned.

Link copied to clipboard
abstract fun getIntegerList(path: String): List<Int>

Gets the specified List of Int configuration value. If the value is not set or not a valid integer list, the default value provided by addDefault is returned. A key present without a value reads as an empty list. Elements that cannot be converted are skipped with a warning.

Link copied to clipboard
abstract fun getKeys(deep: Boolean): Set<String>

Gets all keys present in the config store.

Link copied to clipboard
abstract fun getLong(path: String): Long

Gets the specified Long configuration value. If the value is not set or not a valid long, the default value provided by addDefault is returned.

Link copied to clipboard
abstract fun getLongList(path: String): List<Long>

Gets the specified List of Long configuration value. If the value is not set or not a valid long list, the default value provided by addDefault is returned. A key present without a value reads as an empty list. Elements that cannot be converted are skipped with a warning.

Link copied to clipboard
abstract fun getMap(path: String): Map<String, Any>

Gets the specified flat Map indexed by String configuration value. If the value is not set or not a valid Map, the default value provided by addDefault is returned. A key present without a value reads as an empty map. Entries without a value, lists and nested sections are skipped with a warning. Values are returned as String, whether loaded from the file, set or provided by addDefault: values loaded from the file as typed there (1.10 stays 1.10), other values converted with toString.

Link copied to clipboard
abstract fun getString(path: String): String

Gets the specified String configuration value. If the value is not set or not a valid string, the default value provided by addDefault is returned. Values loaded from the file are returned as typed there (1.10 stays 1.10, 007 stays 007).

Link copied to clipboard
abstract fun getStringList(path: String): List<String>

Gets the specified List of String configuration value. If the value is not set or not a valid string list, the default value provided by addDefault is returned. A key present without a value reads as an empty list. Elements that cannot be converted are skipped with a warning. Elements loaded from the file are returned as typed there (1.10 stays 1.10).

Link copied to clipboard
abstract fun reloadConfig()

Reloads all configuration values from the underlying config representation, for example from file.

Link copied to clipboard
abstract fun remove(path: String)

Removes the value at the specified path.

Link copied to clipboard
abstract fun save()

Persists any changes in configuration values to disk. WARNING: overwrites any changes done to the config file on disk!

Link copied to clipboard
abstract fun saveDefaults()

Stores the default values provided by addDefault for any path that has no user provided value. If the underlying config representation does not exist, it is created and initiated with the default values. A list or map key that is present without a value is written as an empty list or map instead of the default.

Link copied to clipboard
abstract fun set(path: String, value: Any?)

Sets the value in the underlying config. Use save to persist changes.

Link copied to clipboard
abstract fun setComments(path: String, comments: List<String>)

Replaces the comment lines of the key at path. Entries containing line breaks are split into several lines. Applied on the next save.

Link copied to clipboard
open fun warn(message: String)

Reports a problem with a configuration value, e.g. a list element that was skipped because it is invalid. Defaults to the io.github.kraftlin.config logger; wrappers created by wrapConfig use their own logger.