Skip to content

Commit

Permalink
refactor: Align Terminology of VSS model classes / public API
Browse files Browse the repository at this point in the history
VssProperty -> VssNode

close #70
  • Loading branch information
Chrylo committed Feb 28, 2024
1 parent 4a04367 commit 5748884
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ","

Expand All @@ -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 <T : Any> VssProperty<T>.datapoint: Datapoint
val <T : Any> VssLeaf<T>.datapoint: Datapoint
get() {
val stringValue = value.toString()
return when (value::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,11 +71,11 @@ fun <T : VssSpecification> 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 <T : Any> VssProperty<T>.copy(datapoint: Datapoint): VssProperty<T> {
fun <T : Any> VssLeaf<T>.copy(datapoint: Datapoint): VssLeaf<T> {
with(datapoint) {
val value: Any = when (valueCase) {
STRING -> string
Expand Down Expand Up @@ -123,13 +123,13 @@ fun <T : Any> VssProperty<T>.copy(datapoint: Datapoint): VssProperty<T> {
}

/**
* 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 <T : Any> VssProperty<T>.copy(value: T): VssProperty<T> {
val memberProperties = VssProperty::class.memberProperties
fun <T : Any> VssLeaf<T>.copy(value: T): VssLeaf<T> {
val memberProperties = VssLeaf::class.memberProperties
val firstPropertyName = memberProperties.first().name
val valueMap = mapOf(firstPropertyName to value)

Expand All @@ -155,7 +155,7 @@ fun <T : VssSpecification> T.copy(
): T {
val vssSpecifications = consideredHeritage + this
val vssProperty = vssSpecifications
.filterIsInstance<VssProperty<*>>()
.filterIsInstance<VssLeaf<*>>()
.find { it.vssPath == vssPath } ?: return this

val updatedVssProperty = vssProperty.copy(updatedValue)
Expand Down Expand Up @@ -185,7 +185,7 @@ operator fun <T : VssSpecification> 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 <T : Any> VssProperty<T>.invoke(value: T): VssProperty<T> {
operator fun <T : Any> VssLeaf<T>.invoke(value: T): VssLeaf<T> {
return copy(value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
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.
*
* @throws [IllegalArgumentException] if the copied types do not match.
* @throws [NoSuchElementException] if no copy method was found for the class.
*/
operator fun VssProperty<Boolean>.not(): VssProperty<Boolean> {
operator fun VssLeaf<Boolean>.not(): VssLeaf<Boolean> {
return copy(!value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double>.plusAssign(value: Number) {
operator fun VssLeaf<Double>.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<Double>.plus(value: Number): VssProperty<Double> {
operator fun VssLeaf<Double>.plus(value: Number): VssLeaf<Double> {
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<Double>.minusAssign(value: Number) {
operator fun VssLeaf<Double>.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<Double>.minus(value: Number): VssProperty<Double> {
operator fun VssLeaf<Double>.minus(value: Number): VssLeaf<Double> {
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<Double>.divAssign(value: Number) {
operator fun VssLeaf<Double>.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<Double>.div(value: Number): VssProperty<Double> {
operator fun VssLeaf<Double>.div(value: Number): VssLeaf<Double> {
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<Double>.timesAssign(value: Number) {
operator fun VssLeaf<Double>.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<Double>.times(value: Number): VssProperty<Double> {
operator fun VssLeaf<Double>.times(value: Number): VssLeaf<Double> {
return copy(this.value * value.toDouble())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Float>.plusAssign(value: Number) {
operator fun VssLeaf<Float>.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<Float>.plus(value: Number): VssProperty<Float> {
operator fun VssLeaf<Float>.plus(value: Number): VssLeaf<Float> {
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<Float>.minusAssign(value: Number) {
operator fun VssLeaf<Float>.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<Float>.minus(value: Number): VssProperty<Float> {
operator fun VssLeaf<Float>.minus(value: Number): VssLeaf<Float> {
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<Float>.divAssign(value: Number) {
operator fun VssLeaf<Float>.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<Float>.div(value: Number): VssProperty<Float> {
operator fun VssLeaf<Float>.div(value: Number): VssLeaf<Float> {
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<Float>.timesAssign(value: Number) {
operator fun VssLeaf<Float>.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<Float>.times(value: Number): VssProperty<Float> {
operator fun VssLeaf<Float>.times(value: Number): VssLeaf<Float> {
return copy(this.value * +value.toFloat())
}
Loading

0 comments on commit 5748884

Please sign in to comment.