generated from SmartOperatingBlock/kotlin-template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create utility method for digital twin properties
- Loading branch information
1 parent
b697871
commit da9350c
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/infrastructure/digitaltwin/presenter/PropertyConversion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2023. Smart Operating Block | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
package infrastructure.digitaltwin.presenter | ||
|
||
/** Utility module for digital twins operations. */ | ||
object PropertyConversion { | ||
|
||
/** | ||
* Obtain a Digital Twin property and convert it to its [T] type. | ||
* In case it is null or the conversion is not possible then get a [defaultValue]. | ||
*/ | ||
inline fun <reified T> Any?.propertyAs(defaultValue: T): T = | ||
when (this) { | ||
is T -> this | ||
else -> defaultValue | ||
} | ||
} |