Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uchuhimo.konf
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.type.TypeFactory
import com.uchuhimo.konf.annotation.JavaApi
import com.uchuhimo.konf.source.DefaultLoaders
import com.uchuhimo.konf.source.Source
import com.uchuhimo.konf.source.base.kvToTree
import java.util.Deque
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* 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][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.
*/
interface Config : ItemContainer {
/**
* Associate item with specified value without type checking.
*
* @param item config item
* @param value associated value
*/
fun rawSet(item: Item<*>, value: Any?)
/**
* Associate item with specified value.
*
* @param item config item
* @param value associated value
*/
operator fun set(item: Item, value: T)
/**
* Find item with specified name, and associate it with specified value.
*
* @param name item name
* @param value associated value
*/
operator fun set(name: String, value: T)
/**
* Associate item with specified thunk, which can be used to evaluate value for the item.
*
* @param item config item
* @param thunk thunk used to evaluate value for the item
*/
fun lazySet(item: Item, 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.
*
* @param name item name
* @param thunk thunk used to evaluate value for the item
*/
fun lazySet(name: String, thunk: (config: ItemContainer) -> T)
/**
* Discard associated value of specified item.
*
* @param item config item
*/
fun unset(item: Item<*>)
/**
* Discard associated value of item with specified name.
*
* @param name item name
*/
fun unset(name: String)
/**
* Remove all values from the facade layer of this config.
*/
fun clear()
/**
* Whether all required items have values or not.
*
* @return `true` if all required items have values, `false` otherwise
*/
fun containsRequired(): Boolean
/**
* Validate whether all required items have values or not. If not, throws [UnsetValueException].
*
* @return the current config
*/
fun validateRequired(): Config
/**
* Returns a property that can read/set associated value for specified item.
*
* @param item config item
* @return a property that can read/set associated value for specified item
*/
fun property(item: Item): ReadWriteProperty
/**
* Returns a property that can read/set associated value for item with specified name.
*
* @param name item name
* @return a property that can read/set associated value for item with specified name
*/
fun property(name: String): ReadWriteProperty
/**
* Name of facade layer of config.
*
* Layer name provides information for facade layer in a cascading config.
*/
val name: String
/**
* Returns parent of this config, or `null` if this config is a root config.
*/
val parent: Config?
/**
* List of config specs from all layers of this config.
*/
val specs: List
/**
* List of sources from all layers of this config.
*/
val sources: Deque