KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > QueryTreeNodeVector


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.sql.compile.Visitor;
27 import org.apache.derby.iapi.sql.compile.Visitable;
28 import org.apache.derby.iapi.error.StandardException;
29
30 import java.util.Enumeration JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * QueryTreeNodeVector is the root class for all lists of query tree nodes.
35  * It provides a wrapper for java.util.Vector. All
36  * lists of query tree nodes inherit from QueryTreeNodeVector.
37  *
38  * @author Jerry Brenner
39  */

40
41 abstract class QueryTreeNodeVector extends QueryTreeNode
42 {
43     private Vector JavaDoc v = new Vector JavaDoc();
44
45     public final int size()
46     {
47         return v.size();
48     }
49
50     QueryTreeNode elementAt(int index)
51     {
52         return (QueryTreeNode) v.elementAt(index);
53     }
54
55     final void addElement(QueryTreeNode qt)
56     {
57         v.addElement(qt);
58     }
59
60     final void removeElementAt(int index)
61     {
62         v.removeElementAt(index);
63     }
64
65     final void removeElement(QueryTreeNode qt)
66     {
67         v.removeElement(qt);
68     }
69
70     final Object JavaDoc remove(int index)
71     {
72         return((QueryTreeNode) (v.remove(index)));
73     }
74
75     final int indexOf(QueryTreeNode qt)
76     {
77         return v.indexOf(qt);
78     }
79
80     final void setElementAt(QueryTreeNode qt, int index)
81     {
82         v.setElementAt(qt, index);
83     }
84
85     void destructiveAppend(QueryTreeNodeVector qtnv)
86     {
87         nondestructiveAppend(qtnv);
88         qtnv.removeAllElements();
89     }
90
91     void nondestructiveAppend(QueryTreeNodeVector qtnv)
92     {
93         int qtnvSize = qtnv.size();
94         for (int index = 0; index < qtnvSize; index++)
95         {
96             v.addElement(qtnv.elementAt(index));
97         }
98     }
99
100     final void removeAllElements()
101     {
102         v.removeAllElements();
103     }
104
105     final void insertElementAt(QueryTreeNode qt, int index)
106     {
107         v.insertElementAt(qt, index);
108     }
109
110     /**
111      * Format this list as a string
112      *
113      * We can simply iterate through the list. Note each list member
114      * is a QueryTreeNode, and so should have its specialization of
115      * toString defined.
116      *
117      * @return This list formatted as a String
118      */

119     public String JavaDoc toString()
120     {
121         if (SanityManager.DEBUG)
122         {
123             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("");
124
125             for (int index = 0; index < size(); index++)
126             {
127                 buffer.append(elementAt(index).toString()).append("; ");
128             }
129
130             return buffer.toString();
131         }
132         else
133         {
134             return "";
135         }
136     }
137
138     /**
139      * Accept a visitor, and call v.visit()
140      * on child nodes as necessary.
141      *
142      * @param v the visitor
143      *
144      * @exception StandardException on error
145      */

146     public Visitable accept(Visitor v)
147         throws StandardException
148     {
149         Visitable returnNode = v.visit(this);
150     
151         if (v.skipChildren(this))
152         {
153             return returnNode;
154         }
155
156         int size = size();
157         for (int index = 0; index < size; index++)
158         {
159             setElementAt((QueryTreeNode)((QueryTreeNode) elementAt(index)).accept(v), index);
160         }
161         
162         return returnNode;
163     }
164 }
165
Popular Tags