001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.sql.compile.Visitor;
027: import org.apache.derby.iapi.sql.compile.Visitable;
028: import org.apache.derby.iapi.error.StandardException;
029:
030: import java.util.Enumeration;
031: import java.util.Vector;
032:
033: /**
034: * QueryTreeNodeVector is the root class for all lists of query tree nodes.
035: * It provides a wrapper for java.util.Vector. All
036: * lists of query tree nodes inherit from QueryTreeNodeVector.
037: *
038: * @author Jerry Brenner
039: */
040:
041: abstract class QueryTreeNodeVector extends QueryTreeNode {
042: private Vector v = new Vector();
043:
044: public final int size() {
045: return v.size();
046: }
047:
048: QueryTreeNode elementAt(int index) {
049: return (QueryTreeNode) v.elementAt(index);
050: }
051:
052: final void addElement(QueryTreeNode qt) {
053: v.addElement(qt);
054: }
055:
056: final void removeElementAt(int index) {
057: v.removeElementAt(index);
058: }
059:
060: final void removeElement(QueryTreeNode qt) {
061: v.removeElement(qt);
062: }
063:
064: final Object remove(int index) {
065: return ((QueryTreeNode) (v.remove(index)));
066: }
067:
068: final int indexOf(QueryTreeNode qt) {
069: return v.indexOf(qt);
070: }
071:
072: final void setElementAt(QueryTreeNode qt, int index) {
073: v.setElementAt(qt, index);
074: }
075:
076: void destructiveAppend(QueryTreeNodeVector qtnv) {
077: nondestructiveAppend(qtnv);
078: qtnv.removeAllElements();
079: }
080:
081: void nondestructiveAppend(QueryTreeNodeVector qtnv) {
082: int qtnvSize = qtnv.size();
083: for (int index = 0; index < qtnvSize; index++) {
084: v.addElement(qtnv.elementAt(index));
085: }
086: }
087:
088: final void removeAllElements() {
089: v.removeAllElements();
090: }
091:
092: final void insertElementAt(QueryTreeNode qt, int index) {
093: v.insertElementAt(qt, index);
094: }
095:
096: /**
097: * Format this list as a string
098: *
099: * We can simply iterate through the list. Note each list member
100: * is a QueryTreeNode, and so should have its specialization of
101: * toString defined.
102: *
103: * @return This list formatted as a String
104: */
105: public String toString() {
106: if (SanityManager.DEBUG) {
107: StringBuffer buffer = new StringBuffer("");
108:
109: for (int index = 0; index < size(); index++) {
110: buffer.append(elementAt(index).toString()).append("; ");
111: }
112:
113: return buffer.toString();
114: } else {
115: return "";
116: }
117: }
118:
119: /**
120: * Accept a visitor, and call v.visit()
121: * on child nodes as necessary.
122: *
123: * @param v the visitor
124: *
125: * @exception StandardException on error
126: */
127: public Visitable accept(Visitor v) throws StandardException {
128: Visitable returnNode = v.visit(this );
129:
130: if (v.skipChildren(this )) {
131: return returnNode;
132: }
133:
134: int size = size();
135: for (int index = 0; index < size; index++) {
136: setElementAt(
137: (QueryTreeNode) ((QueryTreeNode) elementAt(index))
138: .accept(v), index);
139: }
140:
141: return returnNode;
142: }
143: }
|