Skip to content

Commit aecb9e4

Browse files
committed
chore: Extract VssSignal + VssBranch interface
1 parent 610f9ca commit aecb9e4

File tree

3 files changed

+100
-60
lines changed

3 files changed

+100
-60
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
package org.eclipse.kuksa.vsscore.model
20+
21+
/**
22+
* Defines a [VssNode] which is not a [VssSignal] and only acts as a branch with one or more children. The [type] is
23+
* always "branch".
24+
*/
25+
interface VssBranch : VssNode {
26+
override val type: String
27+
get() = "branch"
28+
}

vss-core/src/main/kotlin/org/eclipse/kuksa/vsscore/model/VssNode.kt

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,48 +69,6 @@ interface VssNode {
6969
get() = null
7070
}
7171

72-
/**
73-
* Defines a [VssNode] which is not a [VssSignal] and only acts as a branch with one or more children. The [type] is
74-
* always "branch".
75-
*/
76-
interface VssBranch : VssNode {
77-
override val type: String
78-
get() = "branch"
79-
}
80-
81-
/**
82-
* Some [VssNode] may have an additional [value] property. These are children [VssSignal] which do not have other
83-
* children.
84-
*/
85-
interface VssSignal<out T : Any> : VssNode {
86-
/**
87-
* A primitive type value.
88-
*/
89-
val value: T
90-
91-
/**
92-
* The VSS data type which is compatible with the Databroker. This may differ from the [value] type because
93-
* Java compatibility needs to be ensured and inline classes like [UInt] (Kotlin) are not known to Java.
94-
*
95-
* ### Example
96-
* Vehicle.Driver.HeartRate:
97-
* datatype: uint16
98-
*
99-
* generates -->
100-
*
101-
* public data class VssHeartRate (
102-
* override val `value`: Int = 0,
103-
* ) : VssSignal<Int> {
104-
* override val dataType: KClass<*>
105-
* get() = UInt:class
106-
* }
107-
*
108-
* To ensure java compatibility [UInt] is not used here for Kotlin (inline class).
109-
*/
110-
val dataType: KClass<*>
111-
get() = value::class
112-
}
113-
11472
/**
11573
* Splits the [VssNode.vssPath] into its parts.
11674
*/
@@ -241,21 +199,3 @@ fun VssNode.findHeritageLine(
241199

242200
return heritageLine
243201
}
244-
245-
/**
246-
* Finds the given [signal] inside the current [VssNode].
247-
*/
248-
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(signal: T): VssNode {
249-
return heritage
250-
.first { it.uuid == signal.uuid }
251-
}
252-
253-
/**
254-
* Finds all [VssSignal] which matches the given [KClass.simpleName]. This is useful when multiple nested objects
255-
* with the same Name exists but are pretty much the same besides the [VssNode.vssPath] etc.
256-
*/
257-
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(type: KClass<T>): Map<String, VssNode> {
258-
return heritage
259-
.filter { it::class.simpleName == type.simpleName }
260-
.associateBy { it.vssPath }
261-
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
package org.eclipse.kuksa.vsscore.model
20+
21+
import kotlin.reflect.KClass
22+
23+
/**
24+
* Some [VssNode] may have an additional [value] property. These are children [VssSignal] which do not have other
25+
* children.
26+
*/
27+
interface VssSignal<out T : Any> : VssNode {
28+
/**
29+
* A primitive type value.
30+
*/
31+
val value: T
32+
33+
/**
34+
* The VSS data type which is compatible with the Databroker. This may differ from the [value] type because
35+
* Java compatibility needs to be ensured and inline classes like [UInt] (Kotlin) are not known to Java.
36+
*
37+
* ### Example
38+
* Vehicle.Driver.HeartRate:
39+
* datatype: uint16
40+
*
41+
* generates -->
42+
*
43+
* public data class VssHeartRate (
44+
* override val `value`: Int = 0,
45+
* ) : VssSignal<Int> {
46+
* override val dataType: KClass<*>
47+
* get() = UInt:class
48+
* }
49+
*
50+
* To ensure java compatibility [UInt] is not used here for Kotlin (inline class).
51+
*/
52+
val dataType: KClass<*>
53+
get() = value::class
54+
}
55+
56+
/**
57+
* Finds the given [signal] inside the current [VssNode].
58+
*/
59+
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(signal: T): VssNode {
60+
return heritage
61+
.first { it.uuid == signal.uuid }
62+
}
63+
64+
/**
65+
* Finds all [VssSignal] which matches the given [KClass.simpleName]. This is useful when multiple nested objects
66+
* with the same Name exists but are pretty much the same besides the [VssNode.vssPath] etc.
67+
*/
68+
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(type: KClass<T>): Map<String, VssNode> {
69+
return heritage
70+
.filter { it::class.simpleName == type.simpleName }
71+
.associateBy { it.vssPath }
72+
}

0 commit comments

Comments
 (0)