In my current project, I have implemented following data structure in Java.
Map<List<String>, Set<Subscriber>> regionSubscriber
= new Hashtable<List<String>, Set<Subscriber>>();
I want to implement following operations on above mentioned data structure.
1) Check the key exists in this map or not ( similar to containsKey(Key)
).
2) Get the Set with key List ( similar to get(key)
).
I have tried with default functions of Map like containskey(Key)
and get(Key)
. But, they are not working because, here the Key is List (not a single Object).
Could you advise me on the implementation of the operations ? Let me know If you need more detail for clarity.
Update: I have written following equals() and hashCode() functions. Kindly check these functions. They are not working. Any corrections on these functions.
public boolean equals(Object obj){
boolean booleanFlag = false;
List<String> regionID = (List<String>) obj;
for(int i=0; i< regionID.size() ; i++) {
if ( regionID.get(i).equals(this.regionIDs.get(i)) ){
booleanFlag = true;
} else {
booleanFlag = false;
}
}
return booleanFlag;
}
@Override
public int hashCode() {
int hashValue = 0;
for(int i=0; i< regionIDs.size(); i++) {
hashValue = hashValue + regionIDs.get(i).hashCode();
}
return hashValue;
}