task4/solution14/src/org/apidesign/apifest08/currency/Pair.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 11 Oct 2008 23:38:46 +0200
changeset 61 58ec6da75f6f
parent 50 task3/solution14/src/org/apidesign/apifest08/currency/Pair.java@03c5c5dc94e7
permissions -rw-r--r--
Copying structure for task4
     1 
     2 package org.apidesign.apifest08.currency;
     3 
     4 
     5 public final class Pair<A,B> {
     6 
     7     private final A first;
     8     private final B second;
     9 
    10     public Pair(A first, B second) {
    11 	this.first = first;
    12 	this.second = second;
    13     }
    14 
    15     public A getFirst() { return first; }
    16     public B getSecond() { return second; }
    17 
    18     @Override
    19     public String toString() {
    20         return "(" + first + ", " + second + ")";
    21     }
    22 
    23     private static boolean equals(Object x, Object y) {
    24 	return (x == null && y == null) || (x != null && x.equals(y));
    25     }
    26 
    27     @Override
    28     public int hashCode() {
    29         int hash = 5;
    30         hash = 59 * hash + (this.first != null ? this.first.hashCode() : 0);
    31         hash = 59 * hash + (this.second != null ? this.second.hashCode() : 0);
    32         return hash;
    33     }
    34 
    35     @Override
    36     public boolean equals(Object obj) {
    37         if (obj == null) {
    38             return false;
    39         }
    40         if (getClass() != obj.getClass()) {
    41             return false;
    42         }
    43         final Pair<A, B> other = (Pair<A, B>) obj;
    44         if (this.first != other.first && (this.first == null || !this.first.equals(other.first))) {
    45             return false;
    46         }
    47         if (this.second != other.second && (this.second == null || !this.second.equals(other.second))) {
    48             return false;
    49         }
    50         return true;
    51     }
    52 
    53 }