class TemplateKey {
private int key1;
private int key2;
}
class TemplateValue {
private int value1;
private int value2;
}
Map templateMap = new HashMap<>();
TemplateKey key = new TemplateKey(1, 2);
TemplateKey value = new TemplateValue(3, 4);
templateMap.put(key, value);
// 検索するkey
TemplateKey searchKey = new TemplateKey(1, 2);
templateMap.containsKey(searchKey) // false
class TemplateKey {
private int key1;
private int key2;
@Override
public boolean equals(Object obj) {
if (obj instanceof TemplateKey) {
TemplateKey condition = (TemplateKey) obj;
return this.key1.equals(condition.key1)
&& this.key2.equals(condition.key2);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hash(key1, key2);
}
}