KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > PathExprImpl


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 XQuark Group.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xpath;
24
25 import java.util.ArrayList JavaDoc;
26
27 public class PathExprImpl /*extends ArrayList*/ implements PathExpr {
28
29     private ArrayList JavaDoc steps = null;
30     private String JavaDoc hashCodeString = null;
31     /**
32      * Default constructor
33      *
34      */

35     public PathExprImpl() {
36         //super();
37
steps = new ArrayList JavaDoc();
38     }
39
40     /**
41      * Other constructor
42      * @param size initial step size
43      */

44     public PathExprImpl(int size) {
45         //super(size);
46
steps = new ArrayList JavaDoc(size);
47     }
48
49     /**
50      * Other constructor
51      * @param steps initial steps
52      */

53     public PathExprImpl(ArrayList JavaDoc steps) {
54 // super(steps.size());
55
// addAll(steps);
56
this.steps = (ArrayList JavaDoc)steps.clone();
57
58     }
59
60     /**
61      *
62      * @param num index of the step to be returned
63      * @return the step with the given index if existing otherwise returns null
64      */

65     public StepExpr getStep(int num) {
66         if (num < 0 || num >= steps.size())
67             return null;
68         return (StepExpr) steps.get(num);
69     }
70
71     /**
72      *
73      * @return the step with the given index if existing otherwise returns null
74      */

75     public ArrayList JavaDoc getSteps() {
76         return steps;
77     }
78
79     /**
80      *
81      * @return the step with the given index if existing otherwise returns null
82      */

83     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
84         PathExprImpl newobj = new PathExprImpl(steps);
85         return newobj;
86     }
87
88     /**
89      *
90      */

91     public String JavaDoc toHashCodeString() {
92         if (hashCodeString != null)
93             return hashCodeString;
94         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
95         for (int i = 0; i < steps.size(); i++) {
96             buf.append(((StepExpr) steps.get(i)).toHashCodeString());
97         }
98         hashCodeString = buf.toString();
99         return hashCodeString;
100     }
101     
102 // public String toString() {
103
// StringBuffer buf = new StringBuffer();
104
// for (int i = 0; i < steps.size(); i++) {
105
// buf.append(((StepExpr) steps.get(i)).toString());
106
// }
107
// return buf.toString();
108
// }
109

110     /**
111      *
112      */

113     public boolean equals(Object JavaDoc o) {
114         if (!(o instanceof PathExprImpl))
115             return false;
116         return toHashCodeString().equals(((PathExprImpl)o).toHashCodeString());
117     }
118
119     // special stuff for hashmap
120
public int hashCode() {
121         String JavaDoc str = ((PathExprImpl)this).toHashCodeString();
122         return str.hashCode();
123     }
124
125 }
126
Popular Tags