Changes
[iotcloud.git] / version2 / src / java / iotcloud / Pair.java
index 73ed6bd440b0858d2c9022c73014b7c07d3088f7..6352fc1dc73cf81c93e3beb5e4a109593bf81044 100644 (file)
@@ -1,12 +1,17 @@
 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() {
@@ -17,7 +22,22 @@ class Pair<A,B> {
                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 + ">";
        }
 }