From d92f286903efda12acec74cc1b5e99687e5447aa Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Mon, 24 Feb 2020 12:09:17 +0100 Subject: Adds calculated properties --- core/src/main/kotlin/model/properties/PropertyContainer.kt | 1 + core/src/main/kotlin/model/properties/properties.kt | 4 ++++ 2 files changed, 5 insertions(+) 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 private constructor( operator fun plus(prop: Property): PropertyContainer = PropertyContainer(map + (prop.key to prop)) + // TODO: Add logic for caching calculated properties inline operator fun get(key: Property.Key): 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 { interface Key val key: Key } + +interface CalculatedProperty: Property.Key { + fun calculate(subject: C): T +} \ No newline at end of file -- cgit