Cicero
02/16/2021, 9:18 AMfun fillFieldsForAttribute(attribute: Map<String, Any>): Any? {
when (localVariable) {
is TruParameter -> {
localVariable.update(attribute)
}
is TruVoltage -> {
localVariable.update(attribute)
}
is TruBatteryState -> {
localVariable.update(attribute)
}
}
return localVariable
}
The classes referenced after “is” are all a subclass of “TruAbstract” which contains “update”
what I tried was
(localVariable as TruAbstract).update(attribute)
return localVariable
and this does not work
Do you see any good idea for a refactor here?Cicero
02/16/2021, 10:03 AMGuillem Ginesta
02/16/2021, 10:13 AMCicero
02/16/2021, 10:23 AMCicero
02/16/2021, 10:23 AMCicero
02/16/2021, 10:24 AMCicero
02/16/2021, 10:24 AMfun updateParameter(
topicMap: Map<String, Any>,
messageConstantKey: String
) {
try {
topicMap.getParameterFromMap(messageConstantKey)
?.let { attribute ->
this.update(attribute)
}
} catch (ex: Exception) {
this.updateValue(topicMap, messageConstantKey)
}
}
Cicero
02/16/2021, 10:25 AMCicero
02/16/2021, 10:25 AMGuillem Ginesta
02/16/2021, 10:29 AMCicero
02/16/2021, 10:36 AMGuillem Ginesta
02/16/2021, 11:02 AMCicero
02/16/2021, 11:44 AMCicero
02/16/2021, 11:44 AM