I am not sure if my title truly reflects what I want to ask.
I have a Java class called Light
with a field: private int state
. I am looking for suggestions on what would be a better / fastest way to access the "state" field as all the Light objects will be stored in a HashMap
. (HashMap's key is int id.) and Light.state gets updated frequently. An example of my operation is: get me all Light
objects that are in state = 2
. after I get everything in state=2
, I might need to change a few to state = 3
.
I thought of bitmap, but I don't store state in the database only in the cache for faster access/modification. I am not sure how to implement bitmap on a field in an object. I am all ears on any possible solutions.
Thanks in advance!
class Light {
private int state = 0;
....other fields....
public void setState(int state) {
this.state = state;
}
}
HashMap<Integer, Light> cache ; // Integer is id not state