1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution14/src/org/apidesign/apifest08/currency/Pair.java Sat Oct 11 23:38:46 2008 +0200
1.3 @@ -0,0 +1,53 @@
1.4 +
1.5 +package org.apidesign.apifest08.currency;
1.6 +
1.7 +
1.8 +public final class Pair<A,B> {
1.9 +
1.10 + private final A first;
1.11 + private final B second;
1.12 +
1.13 + public Pair(A first, B second) {
1.14 + this.first = first;
1.15 + this.second = second;
1.16 + }
1.17 +
1.18 + public A getFirst() { return first; }
1.19 + public B getSecond() { return second; }
1.20 +
1.21 + @Override
1.22 + public String toString() {
1.23 + return "(" + first + ", " + second + ")";
1.24 + }
1.25 +
1.26 + private static boolean equals(Object x, Object y) {
1.27 + return (x == null && y == null) || (x != null && x.equals(y));
1.28 + }
1.29 +
1.30 + @Override
1.31 + public int hashCode() {
1.32 + int hash = 5;
1.33 + hash = 59 * hash + (this.first != null ? this.first.hashCode() : 0);
1.34 + hash = 59 * hash + (this.second != null ? this.second.hashCode() : 0);
1.35 + return hash;
1.36 + }
1.37 +
1.38 + @Override
1.39 + public boolean equals(Object obj) {
1.40 + if (obj == null) {
1.41 + return false;
1.42 + }
1.43 + if (getClass() != obj.getClass()) {
1.44 + return false;
1.45 + }
1.46 + final Pair<A, B> other = (Pair<A, B>) obj;
1.47 + if (this.first != other.first && (this.first == null || !this.first.equals(other.first))) {
1.48 + return false;
1.49 + }
1.50 + if (this.second != other.second && (this.second == null || !this.second.equals(other.second))) {
1.51 + return false;
1.52 + }
1.53 + return true;
1.54 + }
1.55 +
1.56 +}