Check if the card contains all the contents of another card
I am trying to check if a card contains all the contents of another card. For example, I have mapA, which is Map<String, List<String>>
, elements: "1" β ["a", "b"] "2" β ["c", "d"]
another MapB, which is also Map<String, List<String>>
, the elements are: "1" β ["a"] "2" β ["c", "d"],
I want to create a comparison function (mapA, mapB) that will return false in this case.
What's the best way to do this?
thank
source to share
The answer provided by @Jacob G will not work in your case, it will only work in the case of an extra (key, value) pair in MapA. - MapA = {1 "-> [" a "," b "]" 2 "-> [" c "," d "]} and MapB = {1" β ["a", "b"]}.
What you need -
boolean isStrictlyDominate(LinkedHashMap<Integer, HashSet<Integer>> firstMap, LinkedHashMap<Integer, HashSet<Integer>> secondMap){
for (Map.Entry<Integer, HashSet<Integer>> item : secondMap.entrySet()) {
int secondMapKey = item.getKey();
if(firstMap.containsKey(secondMapKey)) {
HashSet<Integer> secondMapValue = item.getValue();
HashSet<Integer> firstMapValue = firstMap.get(secondMapKey) ;
if(!firstMapValue.containsAll(secondMapValue)) {
return false;
}
}
}
return !firstMap.equals(secondMap);
}
(if you don't want to check for strict dominance then just return
true at the end return
)
source to share