Simplify inheritance logic in MutableTypedMeta
This commit is contained in:
parent
bb9afb329f
commit
f79b7faeaf
@ -5,6 +5,7 @@
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- Simplify inheritance logic in `MutableTypedMeta`
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
- MetaProvider `spec` is replaced by `readable`. `listOfSpec` replaced with `listOfReadable`
|
- MetaProvider `spec` is replaced by `readable`. `listOfSpec` replaced with `listOfReadable`
|
||||||
|
@ -159,7 +159,17 @@ public interface MutableTypedMeta<M : MutableTypedMeta<M>> : TypedMeta<M>, Mutab
|
|||||||
*/
|
*/
|
||||||
@DFExperimental
|
@DFExperimental
|
||||||
public fun attach(name: Name, node: M)
|
public fun attach(name: Name, node: M)
|
||||||
override fun get(name: Name): M?
|
|
||||||
|
override fun get(name: Name): M? {
|
||||||
|
tailrec fun M.find(name: Name): M? = if (name.isEmpty()) {
|
||||||
|
self
|
||||||
|
} else {
|
||||||
|
items[name.firstOrNull()!!]?.find(name.cutFirst())
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.find(name)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getOrCreate(name: Name): M
|
override fun getOrCreate(name: Name): M
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,6 @@ package space.kscience.dataforge.meta
|
|||||||
|
|
||||||
import space.kscience.dataforge.misc.ThreadSafe
|
import space.kscience.dataforge.misc.ThreadSafe
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.dataforge.names.cutFirst
|
|
||||||
import space.kscience.dataforge.names.firstOrNull
|
|
||||||
import space.kscience.dataforge.names.isEmpty
|
|
||||||
|
|
||||||
|
|
||||||
internal data class MetaListener(
|
internal data class MetaListener(
|
||||||
@ -39,20 +36,7 @@ public interface ObservableMeta : Meta {
|
|||||||
* A [Meta] which is both observable and mutable
|
* A [Meta] which is both observable and mutable
|
||||||
*/
|
*/
|
||||||
public interface ObservableMutableMeta : ObservableMeta, MutableMeta, MutableTypedMeta<ObservableMutableMeta> {
|
public interface ObservableMutableMeta : ObservableMeta, MutableMeta, MutableTypedMeta<ObservableMutableMeta> {
|
||||||
|
|
||||||
override val self: ObservableMutableMeta get() = this
|
override val self: ObservableMutableMeta get() = this
|
||||||
|
|
||||||
override fun getOrCreate(name: Name): ObservableMutableMeta
|
|
||||||
|
|
||||||
override fun get(name: Name): ObservableMutableMeta? {
|
|
||||||
tailrec fun ObservableMutableMeta.find(name: Name): ObservableMutableMeta? = if (name.isEmpty()) {
|
|
||||||
this
|
|
||||||
} else {
|
|
||||||
items[name.firstOrNull()!!]?.find(name.cutFirst())
|
|
||||||
}
|
|
||||||
|
|
||||||
return find(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal abstract class AbstractObservableMeta : ObservableMeta {
|
internal abstract class AbstractObservableMeta : ObservableMeta {
|
||||||
|
Loading…
Reference in New Issue
Block a user