Map<Integer, Configuration> m
Configuration {
int configNumber;
Map<Integer, Pair<Set<Address>, Set<Integer>>> groupInfo;
}
My map m essentially maps the configNumber to Configuration class. Future configNumber requires information from previous configNumber's values. However, when I add a new configNumber into my map, the second Set<Integer>>
follows with the Set<Integer>>
of the newly put configNumber. For example:
Initial:
- Key:
0
, Value:Configuration(configNum=0, groupInfo={1=([server3, server2, server1],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])})
When I add a new Key, say 1:
Key:
0
, Value:Configuration(configNum=0, groupInfo={1=([server3, server2, server1],[6, 7, 8, 9, 10])})
Key:
1
, Value:Configuration(configNum=1, groupInfo={1=([server3, server2, server1],[6, 7, 8, 9, 10]), 2=([server6, server5, server4],[1, 2, 3, 4, 5])})
As you can see, key 0
's right Set<Integer>
in the pair changes with what was recently put. I thought that this was a problem of reference. But every time I created a new HashMap<>()
and put all the values there before accessing it. Any tips would be appreciated.