Renamed Specification -> Specific

Renamed SpecificationCompanion -> Specification
This commit is contained in:
Alexander Nozik 2019-04-30 14:32:54 +03:00
parent d23c0d3781
commit 902a5f70ab
7 changed files with 21 additions and 21 deletions

View File

@ -4,14 +4,14 @@ import hep.dataforge.meta.*
import hep.dataforge.names.toName
class DataFilter(override val config: Config) : Specification {
class DataFilter(override val config: Config) : Specific {
var from by string()
var to by string()
var pattern by string("*.")
// val prefix by string()
// val suffix by string()
companion object : SpecificationCompanion<DataFilter> {
companion object : Specification<DataFilter> {
override fun wrap(config: Config): DataFilter = DataFilter(config)
}
}

View File

@ -31,7 +31,7 @@ import hep.dataforge.names.toName
*
* @author Alexander Nozik
*/
class NodeDescriptor(override val config: Config) : Specification {
class NodeDescriptor(override val config: Config) : Specific {
/**
* The name of this node
@ -120,7 +120,7 @@ class NodeDescriptor(override val config: Config) : Specification {
//override val descriptor: NodeDescriptor = empty("descriptor")
companion object : SpecificationCompanion<NodeDescriptor> {
companion object : Specification<NodeDescriptor> {
override fun wrap(config: Config): NodeDescriptor = NodeDescriptor(config)

View File

@ -29,7 +29,7 @@ import hep.dataforge.values.ValueType
*
* @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.
@ -121,7 +121,7 @@ class ValueDescriptor(override val config: Config) : Specification {
this.allowedValues = v.map { Value.of(it) }
}
companion object : SpecificationCompanion<ValueDescriptor> {
companion object : Specification<ValueDescriptor> {
override fun wrap(config: Config): ValueDescriptor = ValueDescriptor(config)

View File

@ -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 <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) }
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) }

View File

@ -118,7 +118,7 @@ operator fun <M : MutableMetaNode<M>> M.set(name: Name, value: Any?) {
is MetaItem.NodeItem<*> -> setNode(name, value.node)
}
is Meta -> setNode(name, value)
is Specification -> setNode(name, value.config)
is Specific -> setNode(name, value.config)
else -> setValue(name, Value.of(value))
}
}

View File

@ -3,16 +3,16 @@ package hep.dataforge.meta
/**
* Marker interface for specifications
*/
interface Specification : Configurable {
interface Specific : Configurable {
operator fun get(name: String): MetaItem<Config>? = config[name]
}
/**
* 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
*/
@ -32,31 +32,31 @@ interface SpecificationCompanion<T : Specification> {
fun wrap(meta: Meta): T = wrap(meta.toConfig())
}
fun <T : Specification> specification(wrapper: (Config) -> T): SpecificationCompanion<T> =
object : SpecificationCompanion<T> {
fun <T : Specific> specification(wrapper: (Config) -> T): Specification<T> =
object : Specification<T> {
override fun wrap(config: Config): T = wrapper(config)
}
/**
* 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) }
/**
* 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) }
/**
* 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) }
fun <C : Specification> Specification.spec(
spec: SpecificationCompanion<C>,
fun <C : Specific> Specific.spec(
spec: Specification<C>,
key: String? = null
) = MutableMorphDelegate(config, key) { spec.wrap(it) }

View File

@ -13,13 +13,13 @@ class MetaDelegateTest {
@Test
fun delegateTest() {
class InnerSpec(override val config: Config) : Specification {
class InnerSpec(override val config: Config) : Specific {
var innerValue by string()
}
val innerSpec = specification(::InnerSpec)
val testObject = object : Specification {
val testObject = object : Specific {
override val config: Config = Config()
var myValue by string()
var safeValue by double(2.2)