Renamed Specification -> Specific
Renamed SpecificationCompanion -> Specification
This commit is contained in:
parent
d23c0d3781
commit
902a5f70ab
@ -4,14 +4,14 @@ import hep.dataforge.meta.*
|
|||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
|
|
||||||
|
|
||||||
class DataFilter(override val config: Config) : Specification {
|
class DataFilter(override val config: Config) : Specific {
|
||||||
var from by string()
|
var from by string()
|
||||||
var to by string()
|
var to by string()
|
||||||
var pattern by string("*.")
|
var pattern by string("*.")
|
||||||
// val prefix by string()
|
// val prefix by string()
|
||||||
// val suffix by string()
|
// val suffix by string()
|
||||||
|
|
||||||
companion object : SpecificationCompanion<DataFilter> {
|
companion object : Specification<DataFilter> {
|
||||||
override fun wrap(config: Config): DataFilter = DataFilter(config)
|
override fun wrap(config: Config): DataFilter = DataFilter(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import hep.dataforge.names.toName
|
|||||||
*
|
*
|
||||||
* @author Alexander Nozik
|
* @author Alexander Nozik
|
||||||
*/
|
*/
|
||||||
class NodeDescriptor(override val config: Config) : Specification {
|
class NodeDescriptor(override val config: Config) : Specific {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this node
|
* The name of this node
|
||||||
@ -120,7 +120,7 @@ class NodeDescriptor(override val config: Config) : Specification {
|
|||||||
|
|
||||||
//override val descriptor: NodeDescriptor = empty("descriptor")
|
//override val descriptor: NodeDescriptor = empty("descriptor")
|
||||||
|
|
||||||
companion object : SpecificationCompanion<NodeDescriptor> {
|
companion object : Specification<NodeDescriptor> {
|
||||||
|
|
||||||
override fun wrap(config: Config): NodeDescriptor = NodeDescriptor(config)
|
override fun wrap(config: Config): NodeDescriptor = NodeDescriptor(config)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import hep.dataforge.values.ValueType
|
|||||||
*
|
*
|
||||||
* @author Alexander Nozik
|
* @author Alexander Nozik
|
||||||
*/
|
*/
|
||||||
class ValueDescriptor(override val config: Config) : Specification {
|
class ValueDescriptor(override val config: Config) : Specific {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default for this value. Null if there is no default.
|
* The default for this value. Null if there is no default.
|
||||||
@ -121,7 +121,7 @@ class ValueDescriptor(override val config: Config) : Specification {
|
|||||||
this.allowedValues = v.map { Value.of(it) }
|
this.allowedValues = v.map { Value.of(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : SpecificationCompanion<ValueDescriptor> {
|
companion object : Specification<ValueDescriptor> {
|
||||||
|
|
||||||
override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config)
|
override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config)
|
||||||
|
|
||||||
|
@ -95,8 +95,8 @@ inline fun <reified E : Enum<E>> Configurable.enum(default: E, key: String? = nu
|
|||||||
|
|
||||||
fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key)
|
fun Configurable.node(key: String? = null) = MutableNodeDelegate(config, key)
|
||||||
|
|
||||||
fun <T : Specification> Configurable.spec(spec: SpecificationCompanion<T>, key: String? = null) =
|
fun <T : Specific> Configurable.spec(spec: Specification<T>, key: String? = null) =
|
||||||
MutableMorphDelegate(config, key) { spec.wrap(it) }
|
MutableMorphDelegate(config, key) { spec.wrap(it) }
|
||||||
|
|
||||||
fun <T : Specification> Configurable.spec(builder: (Config) -> T, key: String? = null) =
|
fun <T : Specific> Configurable.spec(builder: (Config) -> T, key: String? = null) =
|
||||||
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
|
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
|
@ -118,7 +118,7 @@ operator fun <M : MutableMetaNode<M>> M.set(name: Name, value: Any?) {
|
|||||||
is MetaItem.NodeItem<*> -> setNode(name, value.node)
|
is MetaItem.NodeItem<*> -> setNode(name, value.node)
|
||||||
}
|
}
|
||||||
is Meta -> setNode(name, value)
|
is Meta -> setNode(name, value)
|
||||||
is Specification -> setNode(name, value.config)
|
is Specific -> setNode(name, value.config)
|
||||||
else -> setValue(name, Value.of(value))
|
else -> setValue(name, Value.of(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,16 @@ package hep.dataforge.meta
|
|||||||
/**
|
/**
|
||||||
* Marker interface for specifications
|
* Marker interface for specifications
|
||||||
*/
|
*/
|
||||||
interface Specification : Configurable {
|
interface Specific : Configurable {
|
||||||
operator fun get(name: String): MetaItem<Config>? = config[name]
|
operator fun get(name: String): MetaItem<Config>? = config[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to apply custom configuration in a type safe way to simple untyped configuration.
|
* Allows to apply custom configuration in a type safe way to simple untyped configuration.
|
||||||
* By convention [Specification] companion should inherit this class
|
* By convention [Specific] companion should inherit this class
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
interface SpecificationCompanion<T : Specification> {
|
interface Specification<T : Specific> {
|
||||||
/**
|
/**
|
||||||
* Update given configuration using given type as a builder
|
* Update given configuration using given type as a builder
|
||||||
*/
|
*/
|
||||||
@ -32,31 +32,31 @@ interface SpecificationCompanion<T : Specification> {
|
|||||||
fun wrap(meta: Meta): T = wrap(meta.toConfig())
|
fun wrap(meta: Meta): T = wrap(meta.toConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Specification> specification(wrapper: (Config) -> T): SpecificationCompanion<T> =
|
fun <T : Specific> specification(wrapper: (Config) -> T): Specification<T> =
|
||||||
object : SpecificationCompanion<T> {
|
object : Specification<T> {
|
||||||
override fun wrap(config: Config): T = wrapper(config)
|
override fun wrap(config: Config): T = wrapper(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply specified configuration to configurable
|
* Apply specified configuration to configurable
|
||||||
*/
|
*/
|
||||||
fun <T : Configurable, C : Specification, S : SpecificationCompanion<C>> T.configure(spec: S, action: C.() -> Unit) =
|
fun <T : Configurable, C : Specific, S : Specification<C>> T.configure(spec: S, action: C.() -> Unit) =
|
||||||
apply { spec.update(config, action) }
|
apply { spec.update(config, action) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update configuration using given specification
|
* Update configuration using given specification
|
||||||
*/
|
*/
|
||||||
fun <C : Specification, S : SpecificationCompanion<C>> Specification.update(spec: S, action: C.() -> Unit) =
|
fun <C : Specific, S : Specification<C>> Specific.update(spec: S, action: C.() -> Unit) =
|
||||||
apply { spec.update(config, action) }
|
apply { spec.update(config, action) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a style based on given specification
|
* Create a style based on given specification
|
||||||
*/
|
*/
|
||||||
fun <C : Specification, S : SpecificationCompanion<C>> S.createStyle(action: C.() -> Unit): Meta =
|
fun <C : Specific, S : Specification<C>> S.createStyle(action: C.() -> Unit): Meta =
|
||||||
Config().also { update(it, action) }
|
Config().also { update(it, action) }
|
||||||
|
|
||||||
|
|
||||||
fun <C : Specification> Specification.spec(
|
fun <C : Specific> Specific.spec(
|
||||||
spec: SpecificationCompanion<C>,
|
spec: Specification<C>,
|
||||||
key: String? = null
|
key: String? = null
|
||||||
) = MutableMorphDelegate(config, key) { spec.wrap(it) }
|
) = MutableMorphDelegate(config, key) { spec.wrap(it) }
|
@ -13,13 +13,13 @@ class MetaDelegateTest {
|
|||||||
@Test
|
@Test
|
||||||
fun delegateTest() {
|
fun delegateTest() {
|
||||||
|
|
||||||
class InnerSpec(override val config: Config) : Specification {
|
class InnerSpec(override val config: Config) : Specific {
|
||||||
var innerValue by string()
|
var innerValue by string()
|
||||||
}
|
}
|
||||||
|
|
||||||
val innerSpec = specification(::InnerSpec)
|
val innerSpec = specification(::InnerSpec)
|
||||||
|
|
||||||
val testObject = object : Specification {
|
val testObject = object : Specific {
|
||||||
override val config: Config = Config()
|
override val config: Config = Config()
|
||||||
var myValue by string()
|
var myValue by string()
|
||||||
var safeValue by double(2.2)
|
var safeValue by double(2.2)
|
||||||
|
Loading…
Reference in New Issue
Block a user