Skip to content

Commit f455d02

Browse files
committed
Implement equals method to compare Pair objects
1 parent 0864927 commit f455d02

File tree

1 file changed

+29
-0
lines changed
  • swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/util

1 file changed

+29
-0
lines changed

swan-assist/src/main/java/de/fraunhofer/iem/swan/assist/util/Pair.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.fraunhofer.iem.swan.assist.util;
22

3+
import java.util.Objects;
4+
35
public class Pair<T,U> {
46
private final T key;
57
private final U value;
@@ -16,4 +18,31 @@ public T getKey() {
1618
public U getValue() {
1719
return this.value;
1820
}
21+
22+
@Override
23+
public boolean equals(Object obj) {
24+
if (this == obj) {
25+
return true;
26+
}
27+
28+
if (obj == null || getClass() != obj.getClass()) {
29+
return false;
30+
}
31+
32+
Pair<?, ?> pair = (Pair<?, ?>) obj;
33+
34+
if (!Objects.equals(key, pair.key)) {
35+
return false;
36+
}
37+
38+
return Objects.equals(value, pair.value);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
int result = key != null ? key.hashCode() : 0;
44+
result = 31 * result + (value != null ? value.hashCode() : 0);
45+
return result;
46+
}
47+
1948
}

0 commit comments

Comments
 (0)