I need to store in an array values from several Numerical items. I have searched in the Forum and the Net but got no luck. What I have in the moment and dont work is
val double arrayEnviroment = newArrayList(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
arrayEnviroment.add(0,(LivingRoom.state as DecimalType).doubleValue) //home_Temp
I get an error saying thet I cannot add NULL values…
Can you help me?
The Rules DSL doesn’t support arrays.
You can use
List<Number> arrayEnvironment = newArrayList
And then a System started rule to populate it. However, in my experience constructs like these tend to be a code angel and the usually is a better approach.
Some thoughts include:
Store the Numbers in Items and use Group as the “array”. See:
Often one will have a number of separate Items which are all related to each other in some way. For example, one might have a Contact on a door and a DateTime to represent when the last time the door was opened. This is easy enough to keep track of if there are only one or two such Items, but if one has a lot of similar Items or is using a lot of genetically coded rules where one cannot hard code the names of the associated Items inside the rule mapping between the Items become…
Often one finds a number of rules that are very similar and that all work on similar Items. One way to solve this problem is through the use of
lambdas but an even more flexible approach is to use Groups.
This Design Pattern presents a step-by-step tutorial for how to use Groups to consolidate and simplify the these several similar rules into one single rule.
The example used will be based on Contact Items that represent door and window sensors. Whenever any of these Contac…
HashMaps often come in handy.
We are not writing code that needs to be wholly generic and shared with lots of people. Sometimes just hard coding numerical values like this in a switch statement is far simpler and just more clear than trying to do things the “right” way.