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
japod@49
     1
japod@49
     2
package org.apidesign.apifest08.currency;
japod@49
     3
japod@49
     4
japod@49
     5
public final class Pair<A,B> {
japod@49
     6
japod@49
     7
    private final A first;
japod@49
     8
    private final B second;
japod@49
     9
japod@49
    10
    public Pair(A first, B second) {
japod@49
    11
	this.first = first;
japod@49
    12
	this.second = second;
japod@49
    13
    }
japod@49
    14
japod@49
    15
    public A getFirst() { return first; }
japod@49
    16
    public B getSecond() { return second; }
japod@49
    17
japod@49
    18
    @Override
japod@49
    19
    public String toString() {
japod@49
    20
        return "(" + first + ", " + second + ")";
japod@49
    21
    }
japod@49
    22
japod@49
    23
    private static boolean equals(Object x, Object y) {
japod@49
    24
	return (x == null && y == null) || (x != null && x.equals(y));
japod@49
    25
    }
japod@49
    26
japod@49
    27
    @Override
japod@49
    28
    public int hashCode() {
japod@49
    29
        int hash = 5;
japod@49
    30
        hash = 59 * hash + (this.first != null ? this.first.hashCode() : 0);
japod@49
    31
        hash = 59 * hash + (this.second != null ? this.second.hashCode() : 0);
japod@49
    32
        return hash;
japod@49
    33
    }
japod@49
    34
japod@49
    35
    @Override
japod@49
    36
    public boolean equals(Object obj) {
japod@49
    37
        if (obj == null) {
japod@49
    38
            return false;
japod@49
    39
        }
japod@49
    40
        if (getClass() != obj.getClass()) {
japod@49
    41
            return false;
japod@49
    42
        }
japod@49
    43
        final Pair<A, B> other = (Pair<A, B>) obj;
japod@49
    44
        if (this.first != other.first && (this.first == null || !this.first.equals(other.first))) {
japod@49
    45
            return false;
japod@49
    46
        }
japod@49
    47
        if (this.second != other.second && (this.second == null || !this.second.equals(other.second))) {
japod@49
    48
            return false;
japod@49
    49
        }
japod@49
    50
        return true;
japod@49
    51
    }
japod@49
    52
japod@49
    53
}