01: /* Pair.java
02:
03: {{IS_NOTE
04:
05: Purpose:
06: Description:
07: History:
08: 2001/8/8, Tom M. Yeh: Created.
09:
10: }}IS_NOTE
11:
12: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.util;
20:
21: import org.zkoss.lang.Objects;
22:
23: /**
24: * A pair of keys. It is used with DualHashSet and DualHashMap to
25: * represent a pair of keys as an object.
26: *
27: * @author tomyeh
28: */
29: public class Pair {
30: /** The first key. */
31: public final Object x;
32: /** The second key. */
33: public final Object y;
34:
35: public Pair(Object x, Object y) {
36: this .x = x;
37: this .y = y;
38: }
39:
40: /** Returns the first value of the pair.
41: */
42: public Object getX() {
43: return this .x;
44: }
45:
46: /** Returns the second value of the pair.
47: */
48: public Object getY() {
49: return this .y;
50: }
51:
52: //-- Object --//
53: public final boolean equals(Object o) {
54: if (!(o instanceof Pair))
55: return false;
56: final Pair pair = (Pair) o;
57: return Objects.equals(x, pair.x) && Objects.equals(y, pair.y);
58: }
59:
60: public final int hashCode() {
61: return Objects.hashCode(x) ^ Objects.hashCode(y);
62: }
63:
64: public String toString() {
65: return '(' + Objects.toString(x) + ", " + Objects.toString(y)
66: + ')';
67: }
68: }
|