1 package jfun.parsec; 2 3 import jfun.util.Misc; 4 5 14 public class Pair<A, B> { 15 private A value1; 16 private B value2; 17 public Pair(){} 18 23 public Pair(A a, B b) { 24 this.value1 = a; 25 this.value2 = b; 26 } 27 30 public A getValue1() { 31 return value1; 32 } 33 36 public void setValue1(A value1) { 37 this.value1 = value1; 38 } 39 42 public B getValue2() { 43 return value2; 44 } 45 48 public void setValue2(B value2) { 49 this.value2 = value2; 50 } 51 public boolean equals(Pair other){ 52 return Misc.equals(value1, other.value1) && Misc.equals(value2, other.value2); 53 } 54 @Override 55 public boolean equals(Object obj) { 56 if(obj instanceof Pair){ 57 return equals((Pair)obj); 58 } 59 else return false; 60 } 61 @Override 62 public int hashCode() { 63 return Misc.hashcode(value1)*31+Misc.hashcode(value2); 64 } 65 @Override 66 public String toString() { 67 return "("+value1+","+value2+")"; 68 } 69 70 } 71 | Popular Tags |