diff options
-rw-r--r-- | core/src/main/kotlin/model/properties/PropertyContainer.kt | 1 | ||||
-rw-r--r-- | core/src/main/kotlin/model/properties/properties.kt | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt index 1b854518..da351569 100644 --- a/core/src/main/kotlin/model/properties/PropertyContainer.kt +++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt @@ -6,6 +6,7 @@ class PropertyContainer<C : Any> private constructor( operator fun <D : C> plus(prop: Property<D>): PropertyContainer<D> = PropertyContainer(map + (prop.key to prop)) + // TODO: Add logic for caching calculated properties inline operator fun <reified T: Any> get(key: Property.Key<C, T>): T? = when (val prop = map[key]) { is T? -> prop else -> throw ClassCastException("Property for $key stored under not matching key type.") diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt index b8965abc..5ff1305a 100644 --- a/core/src/main/kotlin/model/properties/properties.kt +++ b/core/src/main/kotlin/model/properties/properties.kt @@ -4,3 +4,7 @@ interface Property<in C : Any> { interface Key<in C: Any, T: Any> val key: Key<C, *> } + +interface CalculatedProperty<in C: Any, T: Any>: Property.Key<C, T> { + fun calculate(subject: C): T +}
\ No newline at end of file |