ive got a problem to read values from an arraylist which is stored in another array list. my code to store the data works, but i can’t read it.
my code to store the data:
val itemdata = newArrayList()
to read the items in the array “itemdata” i tried:
but i got the error:
‘get’ is not a member of ‘java.lang.Object’;
the reason behind this is to loop trought the oldstateheater array and send the old state to the stored item.
Thanks for help
.get(int) method returns a object. You have to cast it to a Arraylist.
I think you can try it with this (not tested):
val ArrayList data = oldstateheater.get(0)
I’m looking at this code and can’t help but think it’s an XY Problem.
Some additional problems you may encounter is that the Item Object you get for a given Item on one run of the Rule may not be the same Object that you get for the same Object later. As a result, the Item you’ve stored in your ArrayList may become disconnected from the event bus so your sendCommand or postUpdate calls may not work. It’s better to store the Item’s name in this case instead of the Item itself. When using a Map, it’s critical to not use the Item itself as the key.
- Why are you storing the Item and the String representation of it’s state to an ArrayList? Especially when you already have a list of those Items in a Group?
because i need the state at the time the rule was performed
- Why are you using an ArrayList instead of a HashMap using the Item name as the key?
i tried also hashmaps but got the same problem
i didn’t know this funktions
but overall i fixed my funktion with the info from the first comment:
var data = newArrayList()
data = oldstateheater.get(i)
but for now i will change my code to use the new functions
now i changed my code to:
var Map states
how is it possible to restore only ONE of the itemsstates in the MAP “states”?
Thanks for help again
states is a Map. It uses the Item as the key so the following might work.
If it doesn’t work, you’ll need to filter the keys for the one with the name of the Item you want. See Design Pattern: Working with Groups in Rules.
val key = states.keySet.filter[ i | i.name == "MyItem"]