source: trunk/gcc/libjava/javax/swing/tree/TreePath.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.4 KB
Line 
1/* TreePath.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package javax.swing.tree;
39
40// Imports
41import java.io.*;
42
43/**
44 * TreePath
45 * @author Andrew Selkirk
46 */
47public class TreePath implements Serializable {
48
49 //-------------------------------------------------------------
50 // Variables --------------------------------------------------
51 //-------------------------------------------------------------
52
53 /**
54 * path
55 */
56 private Object[] path = null;
57
58
59 //-------------------------------------------------------------
60 // Initialization ---------------------------------------------
61 //-------------------------------------------------------------
62
63 /**
64 * Constructor TreePath
65 * @param path TODO
66 */
67 public TreePath(Object[] path) {
68
69 // Create Path
70 this.path = new Object[path.length];
71 System.arraycopy(path, 0, this.path, 0, path.length);
72
73 } // TreePath()
74
75 /**
76 * Constructor TreePath
77 * @param element TODO
78 */
79 public TreePath(Object element) {
80
81 // Create Path
82 path = new Object[1];
83 path[0] = element;
84
85 } // TreePath()
86
87 /**
88 * Constructor TreePath
89 * @param path TODO
90 * @param element TODO
91 */
92 protected TreePath(TreePath path, Object element) {
93
94 // Variables
95 Object[] treepath;
96
97 // Get Tree Path
98 treepath = path.getPath();
99
100 // Create Tree Path
101 this.path = new Object[treepath.length + 1];
102 System.arraycopy(treepath, 0, this.path, 0, treepath.length);
103 this.path[treepath.length] = element;
104
105 } // TreePath()
106
107 /**
108 * Constructor TreePath
109 * @param path TODO
110 * @param length TODO
111 */
112 protected TreePath(Object[] path, int length) {
113
114 // Create Path
115 this.path = new Object[length];
116 System.arraycopy(path, 0, this.path, 0, length);
117
118 } // TreePath()
119
120 /**
121 * Constructor TreePath
122 */
123 protected TreePath() {
124 path = new Object[0];
125 } // TreePath()
126
127
128 //-------------------------------------------------------------
129 // Methods ----------------------------------------------------
130 //-------------------------------------------------------------
131
132 /**
133 * hashCode
134 * @returns int
135 */
136 public int hashCode() {
137 return getLastPathComponent().hashCode();
138 } // hashCode()
139
140 /**
141 * equals
142 * @param object TODO
143 * @returns boolean
144 */
145 public boolean equals(Object object) {
146
147 // Variables
148 Object[] treepath;
149 int index;
150
151 // Check for TreePath
152 if (object instanceof TreePath) {
153
154 // Get Path Elements
155 treepath = ((TreePath) object).getPath();
156
157 // Check length
158 if (treepath.length != path.length) {
159 return false;
160 } // if
161
162 // Check Elements
163 for (index = 0; index < path.length; index++) {
164 if (treepath[index] != path[index]) {
165 return false;
166 } // if
167 } // for
168
169 // Tree Path's are equals
170 return true;
171
172 } // if
173
174 // Unequal
175 return false;
176
177 } // equals()
178
179 /**
180 * toString
181 * @returns String
182 */
183 public String toString() {
184 return null; // TODO
185 } // toString()
186
187 /**
188 * writeObject
189 * @param value0 TODO
190 * @exception IOException TODO
191 */
192 private void writeObject(ObjectOutputStream value0) throws IOException {
193 // TODO
194 } // writeObject()
195
196 /**
197 * readObject
198 * @param value0 TODO
199 * @exception IOException TODO
200 * @exception ClassNotFoundException TODO
201 */
202 private void readObject(ObjectInputStream value0) throws IOException, ClassNotFoundException {
203 // TODO
204 } // readObject()
205
206 /**
207 * getPath
208 * @returns Object[]
209 */
210 public Object[] getPath() {
211 return path;
212 } // getPath()
213
214 /**
215 * getLastPathComponent
216 * @returns Object
217 */
218 public Object getLastPathComponent() {
219 return path[path.length - 1];
220 } // getLastPathComponent()
221
222 /**
223 * getPathCount
224 * @returns int
225 */
226 public int getPathCount() {
227 return path.length;
228 } // getPathCount()
229
230 /**
231 * getPathComponent
232 * @param position TODO
233 * @returns Object
234 */
235 public Object getPathComponent(int position) {
236 return path[position];
237 } // getPathComponent()
238
239 /**
240 * isDescendant
241 * @param path TODO
242 * @returns boolean
243 */
244 public boolean isDescendant(TreePath path) {
245
246 // Variables
247 Object[] treepath;
248 int index;
249 int index2;
250
251 // Get Descendant path
252 treepath = path.getPath();
253
254 // Locate Start Index
255 index = 0;
256 index2 = 0;
257 while (treepath[index] != this.path[index2]) {
258 index++;
259 } // while
260
261 // Verify Paths
262 while (treepath[index] == this.path[index2]) {
263 index++;
264 index2++;
265 } // while
266
267 // Check for descendant
268 if (index2 != this.path.length) {
269 return false;
270 } // if
271
272 // Is Descendant
273 return true;
274
275 } // isDescendant()
276
277 /**
278 * pathByAddingChild
279 * @param element TODO
280 * @returns TreePath
281 */
282 public TreePath pathByAddingChild(Object element) {
283 return new TreePath(this, element);
284 } // pathByAddingChild()
285
286 /**
287 * getParentPath
288 * @returns TreePath
289 */
290 public TreePath getParentPath() {
291 return new TreePath(this.getPath(), path.length - 1);
292 } // getParentPath()
293
294
295} // TreePath
Note: See TracBrowser for help on using the repository browser.