KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > util > ObjectPair


1 /**
2  * Nov 23, 2004
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.util;
19
20 /**
21  * Simple bean for grouping together a pair of <code>Objects</code>.
22  *
23  * @author hgani
24  * @version $Id: ObjectPair.java,v 1.2 2006/03/18 05:29:42 hgani Exp $
25  */

26 public final class ObjectPair {
27   /**
28    * The first object in the pair.
29    */

30   private Object JavaDoc first;
31   /**
32    * The second object in the pair.
33    */

34   private Object JavaDoc second;
35
36   /**
37    * Creates a new pair instance.
38    *
39    * @param first the first object
40    * @param second the second second
41    */

42   public ObjectPair(Object JavaDoc first, Object JavaDoc second) {
43     super();
44     this.first = first;
45     this.second = second;
46   }
47
48   /**
49    * Returns the first object.
50    *
51    * @return the first
52    */

53   public Object JavaDoc getFirstObject() {
54     return this.first;
55   }
56
57   /**
58    * Returns the second object.
59    *
60    * @return the second
61    */

62   public Object JavaDoc getSecondObject() {
63     return this.second;
64   }
65
66   /** {@inheritDoc} */
67   public boolean equals(Object JavaDoc obj) {
68     if (this == obj) {
69       return true;
70     }
71
72     if (!(obj instanceof ObjectPair)) {
73       return false;
74     }
75
76     ObjectPair temp = (ObjectPair) obj;
77
78     // since this class represents a generic pair of objects, both objects
79
// are taken into account
80
return
81         (this.first == null ?
82             temp.first == null : this.first.equals(temp.first)) &&
83         (this.second == null ?
84             temp.second == null : this.second.equals(temp.second));
85   }
86
87   /** {@inheritDoc} */
88   public int hashCode() {
89     return
90         (this.first == null ? 0 : this.first.hashCode()) ^
91         (this.second == null ? 0 : this.second.hashCode());
92   }
93 }
94
Popular Tags