The background is that I record LastUpdated timestamps of Homematic sensors to fire an alarm after a predefined amount of time (e.g. “sensor not updated since …”) like this:
From time to time I want to clear / reset the whole hashmap which means to set it to an empty hashmap again:
timers = newHashMap
But this is obviously not sufficient because the existing timers are still running and will fire over and over again as they are rescheduled. What I need now is an algorithm to iterate through my existing hashmap to get a hold onto my timers and cancel all of them before I finally reset the hashmap. I have searched the forum but have not found anything useful for my issue.Who can help me with that?
You are right. The item names within the hashmap are not really known but the members of the triggering group definitely are! So now I am looping through its members and test whether they have an associated timer running. That’s it! Thank you, @rossko57!
Thank you, Rich. That works! I tried something “similar” before but it failed somehow. I must have done something wrong… The solution is even shorter now:
It will be impossible for timer to be null so you don’t need that if statement. To remove a key/value pair from a Hashmap you set the value to null so it is impossible to have null values.