Source code: javatools/util/IndexedObject.java
1 /*
2 * IndexedObject.java
3 *
4 * Created on 30 aprile 2002, 18.52
5 Javatools (modified version) - Some useful general classes.
6 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23 */
24
25 package javatools.util;
26
27 /**
28 * An object and an index...
29 * @author Antonio Petrelli
30 * @version 0.0.1
31 */
32 public class IndexedObject extends java.lang.Object {
33
34
35 /** Creates new IndexedObject */
36 public IndexedObject() {
37 refObject = null;
38 index = null;
39 }
40
41 /** Clones this object.
42 * @throws CloneNotSupportedException If you can't clone this.
43 * @return The cloned object.
44 */
45 protected java.lang.Object clone() throws java.lang.CloneNotSupportedException {
46 IndexedObject tempObject;
47 Object tempRefObject, tempIndex;
48
49 tempObject = new IndexedObject();
50 tempRefObject = refObject;
51 tempIndex = index;
52 tempObject.setRefObject(tempRefObject);
53 tempObject.setIndex(tempIndex);
54 return tempObject;
55 }
56
57 /** Checks if an object is equal to this one.
58 * @param obj The object to compare to.
59 * @return <CODE>true</CODE>: the objects are equal;
60 * <CODE>false</CODE>: the object are NOT equal.
61 */
62 public boolean equals(java.lang.Object obj) {
63 IndexedObject tempObject;
64
65 if (obj instanceof IndexedObject) {
66 tempObject = (IndexedObject) obj;
67 if (refObject == null)
68 if (tempObject == null)
69 return true;
70 else
71 return false;
72 else
73 if (tempObject == null)
74 return false;
75 else
76 return refObject.equals(tempObject.getRefObject());
77 }
78 else
79 return refObject.equals(obj);
80 }
81
82 /** Destroys this object.
83 * @throws Throwable If something goes wrong.
84 */
85 protected void finalize() throws java.lang.Throwable {
86 super.finalize();
87 }
88
89 /** Returns a hash code for this object.
90 * @return The requested hash code.
91 */
92 public int hashCode() {
93 if (refObject != null)
94 return refObject.hashCode();
95 else
96 return 0;
97 }
98
99 /** Returns a string representation of this object.
100 * @return The requested string.
101 */
102 public java.lang.String toString() {
103 if (refObject != null)
104 return refObject.toString();
105 else
106 return null;
107 }
108
109 /** Sets the referring object.
110 * @param pRefObject The referring object.
111 */
112 public void setRefObject(Object pRefObject) {
113 refObject = pRefObject;
114 }
115
116 /** Returns the referred object.
117 * @return The referred object.
118 */
119 public Object getRefObject() {
120 return refObject;
121 }
122
123 /** Sets the index for this object.
124 * @param pIndex The index for this object.
125 */
126 public void setIndex(Object pIndex) {
127 index = pIndex;
128 }
129
130 /** Returns the index for this object.
131 * @return The index of the object.
132 */
133 public Object getIndex() {
134 return index;
135 }
136
137 private Object refObject;
138 private Object index;
139 }