package iotcloud;
-class Pair<A,B> {
+class Pair<A, B> {
private A a;
private B b;
+ int hashCode = -1;
Pair(A a, B b) {
- this.a=a;
- this.b=b;
+ this.a = a;
+ this.b = b;
+
+ hashCode = 23;
+ hashCode = hashCode * 31 + a.hashCode();
+ hashCode = hashCode * 31 + b.hashCode();
}
A getFirst() {
return b;
}
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof Pair) {
+ Pair i = (Pair)o;
+ if (a.equals(i.getFirst()) && b.equals(i.getSecond())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public String toString() {
- return "<"+a+","+b+">";
+ return "<" + a + "," + b + ">";
}
}