From 57488844ddfbd33ea93d58521252598716cde511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Wed, 28 Feb 2024 16:17:43 +0100 Subject: [PATCH] refactor: Align Terminology of VSS model classes / public API VssProperty -> VssNode close #70 --- .../org/eclipse/kuksa/DataBrokerConnection.kt | 14 ++++---- .../org/eclipse/kuksa/PropertyListener.kt | 6 ++-- .../kuksa/extension/DataPointExtension.kt | 8 ++--- .../VssSpecificationCopyExtension.kt | 16 ++++----- .../extension/VssSpecificationExtension.kt | 4 +-- .../VssPropertyBooleanExtension.kt | 4 +-- .../vssProperty/VssPropertyDoubleExtension.kt | 34 +++++++++---------- .../vssProperty/VssPropertyFloatExtension.kt | 34 +++++++++---------- .../vssProperty/VssPropertyIntExtension.kt | 34 +++++++++---------- .../vssProperty/VssPropertyLongExtension.kt | 34 +++++++++---------- .../org/eclipse/kuksa/model/Property.kt | 2 +- .../subscription/DataBrokerSubscriber.kt | 8 ++--- .../kuksa/vssSpecification/VssDriver.kt | 18 +++++----- .../VssSpecificationCopyTest.kt | 4 +-- .../kuksa/vssSpecification/VssVehicle.kt | 14 ++++---- .../kuksa/vsscore/model/VssSpecification.kt | 18 +++++----- .../eclipse/kuksa/vsscore/model/VssVehicle.kt | 4 +-- .../spec/VssSpecificationSpecModel.kt | 11 +++--- 18 files changed, 133 insertions(+), 134 deletions(-) diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt index ee7db7f9..a5b8328e 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/DataBrokerConnection.kt @@ -37,7 +37,7 @@ import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.proto.v1.Types.Datapoint import org.eclipse.kuksa.proto.v1.Types.Field import org.eclipse.kuksa.subscription.DataBrokerSubscriber -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import org.eclipse.kuksa.vsscore.model.heritage import org.eclipse.kuksa.vsscore.model.vssProperties @@ -112,10 +112,10 @@ class DataBrokerConnection internal constructor( } /** - * Subscribes to the specified [VssSpecification] with the provided [VssSpecificationListener]. Only a [VssProperty] + * Subscribes to the specified [VssSpecification] with the provided [VssSpecificationListener]. Only a [VssLeaf] * can be subscribed because they have an actual value. When provided with any parent [VssSpecification] then this - * [subscribe] method will find all [VssProperty] children and subscribes them instead. Once subscribed the - * application will be notified about any changes to every subscribed [VssProperty]. The [fields] can be used to + * [subscribe] method will find all [VssLeaf] children and subscribes them instead. Once subscribed the + * application will be notified about any changes to every subscribed [VssLeaf]. The [fields] can be used to * subscribe to different information of the [specification]. The default for the [fields] parameter is a list with * a single [Types.Field.FIELD_VALUE] entry. * @@ -210,14 +210,14 @@ class DataBrokerConnection internal constructor( } /** - * Only a [VssProperty] can be updated because they have an actual value. When provided with any parent - * [VssSpecification] then this [update] method will find all [VssProperty] children and updates their corresponding + * Only a [VssLeaf] can be updated because they have an actual value. When provided with any parent + * [VssSpecification] then this [update] method will find all [VssLeaf] children and updates their corresponding * [fields] instead. * Compared to [update] with only one [Property] and [Datapoint], here multiple [SetResponse] will be returned * because a [VssSpecification] may consists of multiple values which may need to be updated. * * @throws DataBrokerException in case the connection to the DataBroker is no longer active - * @throws IllegalArgumentException if the [VssProperty] could not be converted to a [Datapoint]. + * @throws IllegalArgumentException if the [VssLeaf] could not be converted to a [Datapoint]. */ @JvmOverloads suspend fun update( diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/PropertyListener.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/PropertyListener.kt index 50f0af6a..617eb786 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/PropertyListener.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/PropertyListener.kt @@ -24,9 +24,9 @@ import org.eclipse.kuksa.proto.v1.KuksaValV1 import org.eclipse.kuksa.vsscore.model.VssSpecification /** - * The Listener is used to notify about changes to subscribed properties. When registering the listener to - * Vehicle.ADAS.ABS this listener will also be notified about changes of sub-properties e.g. Vehicle.ADAS.ABS.IsEnabled - * or Vehicle.ADAS.ABS.IsEngaged. + * The Listener is used to notify about changes to subscribed [org.eclipse.kuksa.model.Property]. When registering the + * listener to Vehicle.ADAS.ABS this listener will also be notified about changes of children e.g. + * Vehicle.ADAS.ABS.IsEnabled or Vehicle.ADAS.ABS.IsEngaged. */ interface PropertyListener : Listener { /** diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataPointExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataPointExtension.kt index 8c008667..3ecd3e8a 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataPointExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/DataPointExtension.kt @@ -24,7 +24,7 @@ import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.proto.v1.Types.BoolArray import org.eclipse.kuksa.proto.v1.Types.Datapoint import org.eclipse.kuksa.proto.v1.Types.Datapoint.ValueCase -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf private const val CSV_DELIMITER = "," @@ -35,11 +35,11 @@ val Types.Metadata.valueType: ValueCase get() = dataType.dataPointValueCase /** - * Converts the [VssProperty.value] into a [Datapoint] object. + * Converts the [VssLeaf.value] into a [Datapoint] object. * - * @throws IllegalArgumentException if the [VssProperty] could not be converted to a [Datapoint]. + * @throws IllegalArgumentException if the [VssLeaf] could not be converted to a [Datapoint]. */ -val VssProperty.datapoint: Datapoint +val VssLeaf.datapoint: Datapoint get() { val stringValue = value.toString() return when (value::class) { diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationCopyExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationCopyExtension.kt index 8a35c233..9d28e52f 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationCopyExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationCopyExtension.kt @@ -22,7 +22,7 @@ package org.eclipse.kuksa.extension import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.proto.v1.Types.Datapoint import org.eclipse.kuksa.proto.v1.Types.Datapoint.ValueCase.* -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import org.eclipse.kuksa.vsscore.model.findHeritageLine import org.eclipse.kuksa.vsscore.model.heritage @@ -71,11 +71,11 @@ fun T.deepCopy(generation: Int = 0, vararg changedHeritag } /** - * Creates a copy of a [VssProperty] where the [VssProperty.value] is changed to the given [Datapoint]. + * Creates a copy of a [VssLeaf] where the [VssLeaf.value] is changed to the given [Datapoint]. */ // The actual value type is unknown but it is expected that the casted [valueCase] is valid if no exception was thrown. @Suppress("UNCHECKED_CAST") -fun VssProperty.copy(datapoint: Datapoint): VssProperty { +fun VssLeaf.copy(datapoint: Datapoint): VssLeaf { with(datapoint) { val value: Any = when (valueCase) { STRING -> string @@ -123,13 +123,13 @@ fun VssProperty.copy(datapoint: Datapoint): VssProperty { } /** - * Calls the generated copy method of the data class for the [VssProperty] and returns a new copy with the new [value]. + * Calls the generated copy method of the data class for the [VssLeaf] and returns a new copy with the new [value]. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -fun VssProperty.copy(value: T): VssProperty { - val memberProperties = VssProperty::class.memberProperties +fun VssLeaf.copy(value: T): VssLeaf { + val memberProperties = VssLeaf::class.memberProperties val firstPropertyName = memberProperties.first().name val valueMap = mapOf(firstPropertyName to value) @@ -155,7 +155,7 @@ fun T.copy( ): T { val vssSpecifications = consideredHeritage + this val vssProperty = vssSpecifications - .filterIsInstance>() + .filterIsInstance>() .find { it.vssPath == vssPath } ?: return this val updatedVssProperty = vssProperty.copy(updatedValue) @@ -185,7 +185,7 @@ operator fun T.invoke(vararg property: VssSpecification): * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.invoke(value: T): VssProperty { +operator fun VssLeaf.invoke(value: T): VssLeaf { return copy(value) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationExtension.kt index e7c9a579..6e8496ea 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/VssSpecificationExtension.kt @@ -20,12 +20,12 @@ package org.eclipse.kuksa.extension import org.eclipse.kuksa.model.Property import org.eclipse.kuksa.proto.v1.Types -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import org.eclipse.kuksa.vsscore.model.vssProperties /** - * Finds all [VssProperty] heirs for the [VssSpecification] and converts them into a collection of [Property]. + * Finds all [VssLeaf] heirs for the [VssSpecification] and converts them into a collection of [Property]. */ fun VssSpecification.createProperties( vararg fields: Types.Field = arrayOf(Types.Field.FIELD_VALUE), diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyBooleanExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyBooleanExtension.kt index 8544834c..0bafa2f6 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyBooleanExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyBooleanExtension.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.extension.vssProperty import org.eclipse.kuksa.extension.copy -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf /** * Convenience operator for [copy] with a [Boolean] value which will be inverted. @@ -27,6 +27,6 @@ import org.eclipse.kuksa.vsscore.model.VssProperty * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.not(): VssProperty { +operator fun VssLeaf.not(): VssLeaf { return copy(!value) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyDoubleExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyDoubleExtension.kt index 37ef935b..072255af 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyDoubleExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyDoubleExtension.kt @@ -19,86 +19,86 @@ package org.eclipse.kuksa.extension.vssProperty import org.eclipse.kuksa.extension.copy -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plusAssign(value: Number) { +operator fun VssLeaf.plusAssign(value: Number) { copy(this.value + value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plus(value: Number): VssProperty { +operator fun VssLeaf.plus(value: Number): VssLeaf { return copy(this.value + value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minusAssign(value: Number) { +operator fun VssLeaf.minusAssign(value: Number) { copy(this.value - value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minus(value: Number): VssProperty { +operator fun VssLeaf.minus(value: Number): VssLeaf { return copy(this.value - value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.divAssign(value: Number) { +operator fun VssLeaf.divAssign(value: Number) { copy(this.value / value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.div(value: Number): VssProperty { +operator fun VssLeaf.div(value: Number): VssLeaf { return copy(this.value / value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.timesAssign(value: Number) { +operator fun VssLeaf.timesAssign(value: Number) { copy(this.value * value.toDouble()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.times(value: Number): VssProperty { +operator fun VssLeaf.times(value: Number): VssLeaf { return copy(this.value * value.toDouble()) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyFloatExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyFloatExtension.kt index 91d090f0..cefadaa7 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyFloatExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyFloatExtension.kt @@ -19,86 +19,86 @@ package org.eclipse.kuksa.extension.vssProperty import org.eclipse.kuksa.extension.copy -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plusAssign(value: Number) { +operator fun VssLeaf.plusAssign(value: Number) { copy(this.value + value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plus(value: Number): VssProperty { +operator fun VssLeaf.plus(value: Number): VssLeaf { return copy(this.value + value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minusAssign(value: Number) { +operator fun VssLeaf.minusAssign(value: Number) { copy(this.value - +value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minus(value: Number): VssProperty { +operator fun VssLeaf.minus(value: Number): VssLeaf { return copy(this.value - +value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.divAssign(value: Number) { +operator fun VssLeaf.divAssign(value: Number) { copy(this.value / +value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.div(value: Number): VssProperty { +operator fun VssLeaf.div(value: Number): VssLeaf { return copy(this.value / +value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.timesAssign(value: Number) { +operator fun VssLeaf.timesAssign(value: Number) { copy(this.value * +value.toFloat()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.times(value: Number): VssProperty { +operator fun VssLeaf.times(value: Number): VssLeaf { return copy(this.value * +value.toFloat()) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyIntExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyIntExtension.kt index 3a8baf41..d2b905bb 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyIntExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyIntExtension.kt @@ -19,86 +19,86 @@ package org.eclipse.kuksa.extension.vssProperty import org.eclipse.kuksa.extension.copy -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plusAssign(value: Number) { +operator fun VssLeaf.plusAssign(value: Number) { copy(this.value + value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plus(value: Number): VssProperty { +operator fun VssLeaf.plus(value: Number): VssLeaf { return copy(this.value + value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minusAssign(value: Number) { +operator fun VssLeaf.minusAssign(value: Number) { copy(this.value - value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minus(value: Number): VssProperty { +operator fun VssLeaf.minus(value: Number): VssLeaf { return copy(this.value - value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.divAssign(value: Number) { +operator fun VssLeaf.divAssign(value: Number) { copy(this.value / value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.div(value: Number): VssProperty { +operator fun VssLeaf.div(value: Number): VssLeaf { return copy(this.value / value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.timesAssign(value: Number) { +operator fun VssLeaf.timesAssign(value: Number) { copy(this.value * value.toInt()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.times(value: Number): VssProperty { +operator fun VssLeaf.times(value: Number): VssLeaf { return copy(this.value * value.toInt()) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyLongExtension.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyLongExtension.kt index 716d3b19..d8bf749c 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyLongExtension.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/extension/vssProperty/VssPropertyLongExtension.kt @@ -19,86 +19,86 @@ package org.eclipse.kuksa.extension.vssProperty import org.eclipse.kuksa.extension.copy -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plusAssign(value: Number) { +operator fun VssLeaf.plusAssign(value: Number) { copy(this.value + value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by adding [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by adding [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.plus(value: Number): VssProperty { +operator fun VssLeaf.plus(value: Number): VssLeaf { return copy(this.value + value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minusAssign(value: Number) { +operator fun VssLeaf.minusAssign(value: Number) { copy(this.value - value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by subtracting [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by subtracting [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.minus(value: Number): VssProperty { +operator fun VssLeaf.minus(value: Number): VssLeaf { return copy(this.value - value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.divAssign(value: Number) { +operator fun VssLeaf.divAssign(value: Number) { copy(this.value / value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by dividing [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by dividing [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. * @throws [ArithmeticException] if divided by zero. */ -operator fun VssProperty.div(value: Number): VssProperty { +operator fun VssLeaf.div(value: Number): VssLeaf { return copy(this.value / value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.timesAssign(value: Number) { +operator fun VssLeaf.timesAssign(value: Number) { copy(this.value * value.toLong()) } /** - * Convenience operator for [copy] which updates the [VssProperty.value] by multiplying [value] to it. + * Convenience operator for [copy] which updates the [VssLeaf.value] by multiplying [value] to it. * * @throws [IllegalArgumentException] if the copied types do not match. * @throws [NoSuchElementException] if no copy method was found for the class. */ -operator fun VssProperty.times(value: Number): VssProperty { +operator fun VssLeaf.times(value: Number): VssLeaf { return copy(this.value * value.toLong()) } diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/model/Property.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/model/Property.kt index b5bffda8..57aece91 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/model/Property.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/model/Property.kt @@ -32,7 +32,7 @@ data class Property( val vssPath: String, /** - * The corresponding field type of the Property. The default is [FIELD_VALUE]. + * The corresponding field type of the [Property]. The default is [FIELD_VALUE]. */ val fields: Collection = listOf(FIELD_VALUE), ) diff --git a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/subscription/DataBrokerSubscriber.kt b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/subscription/DataBrokerSubscriber.kt index f95678fe..306942a7 100644 --- a/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/subscription/DataBrokerSubscriber.kt +++ b/kuksa-sdk/src/main/kotlin/org/eclipse/kuksa/subscription/DataBrokerSubscriber.kt @@ -27,7 +27,7 @@ import org.eclipse.kuksa.VssSpecificationListener import org.eclipse.kuksa.extension.TAG import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.proto.v1.Types.Field -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification /** @@ -76,10 +76,10 @@ internal class DataBrokerSubscriber(private val dataBrokerTransporter: DataBroke } /** - * Subscribes to the specified [VssSpecification] with the provided [VssSpecificationListener]. Only a [VssProperty] + * Subscribes to the specified [VssSpecification] with the provided [VssSpecificationListener]. Only a [VssLeaf] * can be subscribed because they have an actual value. When provided with any parent [VssSpecification] then this - * [subscribe] method will find all [VssProperty] children and subscribes them instead. Once subscribed the - * application will be notified about any changes to every subscribed [VssProperty]. The [field] can be used to + * [subscribe] method will find all [VssLeaf] children and subscribes them instead. Once subscribed the + * application will be notified about any changes to every subscribed [VssLeaf]. The [field] can be used to * subscribe to different information of the [specification]. The default for the [field] parameter is a single * [Types.Field.FIELD_VALUE] entry. * diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssDriver.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssDriver.kt index 6d3f6999..9b9e447e 100644 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssDriver.kt +++ b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssDriver.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.vssSpecification -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import kotlin.reflect.KClass @@ -63,7 +63,7 @@ data class VssDriver @JvmOverloads constructor( data class VssHeartRate @JvmOverloads constructor( override val `value`: Int = 0, - ) : VssProperty { + ) : VssLeaf { override val comment: String get() = "" @@ -89,7 +89,7 @@ data class VssDriver @JvmOverloads constructor( data class VssAttentiveProbability @JvmOverloads constructor( override val `value`: Float = 0f, -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -114,7 +114,7 @@ data class VssAttentiveProbability @JvmOverloads constructor( data class VssDistractionLevel @JvmOverloads constructor( override val `value`: Float = 0f, -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -139,7 +139,7 @@ data class VssDistractionLevel @JvmOverloads constructor( data class VssFatigueLevel @JvmOverloads constructor( override val `value`: Float = 0f, -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -190,7 +190,7 @@ data class VssIdentifier @JvmOverloads constructor( data class VssIssuer @JvmOverloads constructor( override val `value`: String = "", -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -216,7 +216,7 @@ data class VssIssuer @JvmOverloads constructor( data class VssSubject @JvmOverloads constructor( override val `value`: String = "", -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -241,7 +241,7 @@ data class VssSubject @JvmOverloads constructor( data class VssIsEyesOnRoad @JvmOverloads constructor( override val `value`: Boolean = false, -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" @@ -266,7 +266,7 @@ data class VssIsEyesOnRoad @JvmOverloads constructor( data class VssIsHandsOnWheel @JvmOverloads constructor( override val `value`: Boolean = false, -) : VssProperty { +) : VssLeaf { override val comment: String get() = "" diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt index 8499acd2..a9102ce2 100644 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt +++ b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt @@ -30,14 +30,14 @@ import org.eclipse.kuksa.extension.invoke import org.eclipse.kuksa.extension.vssProperty.not import org.eclipse.kuksa.proto.v1.Types import org.eclipse.kuksa.test.kotest.Unit -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf class VssSpecificationCopyTest : BehaviorSpec({ tags(Unit) given("A specification") { val vehicle = VssVehicle() - val driverHeartRate: VssProperty = vehicle.driver.heartRate + val driverHeartRate: VssLeaf = vehicle.driver.heartRate and("a changed heritage line") { val newValue = 70 diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssVehicle.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssVehicle.kt index 6abebf3d..a3431570 100644 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssVehicle.kt +++ b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssVehicle.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.vssSpecification -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import kotlin.reflect.KClass @@ -68,7 +68,7 @@ data class VssPassenger( override val type: String = "sensor", override val comment: String = "", override val value: Int = 80, - ) : VssProperty { + ) : VssLeaf { override val parentClass: KClass<*> get() = VssPassenger::class } @@ -81,7 +81,7 @@ data class VssValueInt( override val type: String = "sensor", override val comment: String = "", override val value: Int = 0, -) : VssProperty +) : VssLeaf data class VssValueFloat( override val uuid: String = "Value", @@ -90,7 +90,7 @@ data class VssValueFloat( override val type: String = "sensor", override val comment: String = "", override val value: Float = 0f, -) : VssProperty +) : VssLeaf data class VssValueDouble( override val uuid: String = "Value", @@ -99,7 +99,7 @@ data class VssValueDouble( override val type: String = "sensor", override val comment: String = "", override val value: Double = 0.0, -) : VssProperty +) : VssLeaf data class VssValueLong( override val uuid: String = "Value", @@ -108,7 +108,7 @@ data class VssValueLong( override val type: String = "sensor", override val comment: String = "", override val value: Long = 0L, -) : VssProperty +) : VssLeaf data class VssInvalid( override val uuid: String = "Invalid", @@ -117,4 +117,4 @@ data class VssInvalid( override val type: String = "", override val comment: String = "", override val value: Exception = Exception(), -) : VssProperty +) : VssLeaf diff --git a/vss-core/src/main/java/org/eclipse/kuksa/vsscore/model/VssSpecification.kt b/vss-core/src/main/java/org/eclipse/kuksa/vsscore/model/VssSpecification.kt index 48747baa..6e402f7b 100644 --- a/vss-core/src/main/java/org/eclipse/kuksa/vsscore/model/VssSpecification.kt +++ b/vss-core/src/main/java/org/eclipse/kuksa/vsscore/model/VssSpecification.kt @@ -55,7 +55,7 @@ interface VssSpecification : VssNode { /** * Some [VssSpecification] may have an additional [value] property. These are children which are not parents. */ -interface VssProperty : VssSpecification { +interface VssLeaf : VssSpecification { val value: T } @@ -118,12 +118,12 @@ val VssSpecification.heritage: Collection get() = children.toList() + children.flatMap { it.heritage } /** - * Finds the latest generation in the form of [VssProperty] for the current [VssSpecification]. + * Finds the latest generation in the form of [VssLeaf] for the current [VssSpecification]. */ -val VssSpecification.vssProperties: Collection> +val VssSpecification.vssProperties: Collection> get() = heritage .ifEmpty { setOf(this) } - .filterIsInstance>() + .filterIsInstance>() /** * Uses the [variablePrefix] to generate a unique variable name. The first character is at least lowercased. @@ -192,19 +192,19 @@ fun VssSpecification.findHeritageLine( /** * Finds the given [property] inside the current [VssSpecification]. */ -fun , V : Any> VssSpecification.findProperty(property: VssProperty): VssProperty { +fun , V : Any> VssSpecification.findProperty(property: VssLeaf): VssLeaf { return heritage - .filterIsInstance>() + .filterIsInstance>() .first { it.uuid == property.uuid } } /** - * Finds all [VssProperty] which matches the given [KClass.simpleName]. This is useful when multiple nested objects + * Finds all [VssLeaf] which matches the given [KClass.simpleName]. This is useful when multiple nested objects * with the same Name exists but are pretty much the same besides the [VssSpecification.vssPath] etc. */ -fun , V : Any> VssSpecification.findProperties(type: KClass): Map> { +fun , V : Any> VssSpecification.findProperties(type: KClass): Map> { return heritage - .filterIsInstance>() + .filterIsInstance>() .filter { it::class.simpleName == type.simpleName } .associateBy { it.vssPath } } diff --git a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt index 68e0bac9..2cc80336 100644 --- a/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt +++ b/vss-core/src/test/java/org/eclipse/kuksa/vsscore/model/VssVehicle.kt @@ -66,7 +66,7 @@ data class VssDriver( override val type: String = "sensor", override val comment: String = "", override val value: Int = 100, - ) : VssProperty { + ) : VssLeaf { override val parentClass: KClass<*> get() = VssDriver::class } @@ -92,7 +92,7 @@ data class VssPassenger( override val type: String = "sensor", override val comment: String = "", override val value: Int = 80, - ) : VssProperty { + ) : VssLeaf { override val parentClass: KClass<*> get() = VssPassenger::class } diff --git a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/spec/VssSpecificationSpecModel.kt b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/spec/VssSpecificationSpecModel.kt index eba569b2..5a0efe34 100644 --- a/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/spec/VssSpecificationSpecModel.kt +++ b/vss-processor/src/main/kotlin/org/eclipse/kuksa/vssprocessor/spec/VssSpecificationSpecModel.kt @@ -33,7 +33,7 @@ import com.squareup.kotlinpoet.TypeSpec import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.asTypeName import org.eclipse.kuksa.vsscore.model.VssNode -import org.eclipse.kuksa.vsscore.model.VssProperty +import org.eclipse.kuksa.vsscore.model.VssLeaf import org.eclipse.kuksa.vsscore.model.VssSpecification import org.eclipse.kuksa.vsscore.model.className import org.eclipse.kuksa.vsscore.model.name @@ -121,7 +121,7 @@ internal class VssSpecificationSpecModel( // Final leafs should ONLY implement the vss property interface superInterfaces.clear() - val vssPropertyInterface = VssProperty::class + val vssPropertyInterface = VssLeaf::class .asTypeName() .plusParameter(datatypeProperty) superInterfaces.add(vssPropertyInterface) @@ -292,13 +292,12 @@ internal class VssSpecificationSpecModel( val propertySpecs = mutableListOf() val members = VssNode::class.declaredMemberProperties + val setTypeName = Set::class.parameterizedBy(VssSpecification::class) + val classTypeName = KClass::class.asClassName().parameterizedBy(STAR).copy(nullable = true) members.forEach { member -> val memberName = member.name - val memberType = member.returnType.asTypeName() - val setTypeName = Set::class.parameterizedBy(VssSpecification::class) - val classTypeName = KClass::class.asClassName().parameterizedBy(STAR).copy(nullable = true) - val propertySpec: PropertySpec? = when (memberType) { + val propertySpec: PropertySpec? = when (val memberType = member.returnType.asTypeName()) { setTypeName -> createSetSpec(memberName, memberType) classTypeName -> createParentSpec(memberName, memberType) else -> null