01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package javax.swing.text.html.parser;
18:
19: /**
20: * This class implements a generic pair.
21: */
22: final class Pair<E, T> {
23: private E comp1;
24:
25: private T comp2;
26:
27: /**
28: * @param comp1
29: * first component
30: * @param comp2
31: * second component
32: */
33: public Pair(E comp1, T comp2) {
34: this .comp1 = comp1;
35: this .comp2 = comp2;
36: }
37:
38: /**
39: * @return the first component of pair
40: */
41: public final E getFirst() {
42: return comp1;
43: }
44:
45: /**
46: * @return the second component of pair
47: */
48: public final T getSecond() {
49: return comp2;
50: }
51:
52: /**
53: * @param o
54: * the object that will be compared for equality.
55: * @return <code>true</code> if <code>obj</code> is instance of the
56: * class <code>Pair</code>, else return <code>false</code>
57: */
58: public final boolean equals(Object o) {
59:
60: if (o == null)
61: return false;
62: if (o == this )
63: return true;
64: if (!(o instanceof Pair))
65: return false;
66: Pair oPair = (Pair) o;
67: return (this .comp1.equals(oPair.comp1) && this .comp2
68: .equals(oPair.comp2));
69: }
70:
71: /**
72: * @return the hash code for this object.
73: */
74: public final int hashCode() {
75: return this .comp1.hashCode() ^ this .comp2.hashCode();
76: }
77:
78: /**
79: * @return a description of the contained of an object of this class
80: */
81: public final String toString() {
82: return "PAIR = first: " + comp1 + " | " + " second: " + comp2;
83: }
84: }
|