01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: Pair.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.datastructures;
09:
10: public class Pair<FirstType, SecondType> implements Cloneable {
11: private FirstType mFirst = null;
12: private SecondType mSecond = null;
13:
14: public Pair() {
15: }
16:
17: public Pair(FirstType first, SecondType second) {
18: setFirst(first);
19: setSecond(second);
20: }
21:
22: public FirstType getFirst() {
23: return mFirst;
24: }
25:
26: public void setFirst(FirstType first) {
27: mFirst = first;
28: }
29:
30: public SecondType getSecond() {
31: return mSecond;
32: }
33:
34: public void setSecond(SecondType second) {
35: mSecond = second;
36: }
37:
38: public boolean equals(Object other) {
39: if (this == other) {
40: return true;
41: }
42:
43: if (null == other) {
44: return false;
45: }
46:
47: if (!(other instanceof Pair)) {
48: return false;
49: }
50:
51: Pair other_pair = (Pair) other;
52: if (getFirst() != null || other_pair.getFirst() != null) {
53: if (null == getFirst() || null == other_pair.getFirst()) {
54: return false;
55: }
56: if (!other_pair.getFirst().equals(getFirst())) {
57: return false;
58: }
59: }
60: if (getSecond() != null || other_pair.getSecond() != null) {
61: if (null == getSecond() || null == other_pair.getSecond()) {
62: return false;
63: }
64: if (!other_pair.getSecond().equals(getSecond())) {
65: return false;
66: }
67: }
68:
69: return true;
70: }
71:
72: public Pair clone() throws CloneNotSupportedException {
73: return (Pair) super .clone();
74: }
75:
76: public int hashCode() {
77: return mFirst.hashCode() * mSecond.hashCode();
78: }
79: }
|