KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > parser > hinttree > HintTree


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
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 /*
24  * CData.java
25  *
26  * Created on 25 juin 2002, 15:46
27  */

28
29 package org.xquark.xquery.parser.hinttree;
30
31 import java.util.ArrayList JavaDoc;
32
33 import org.xquark.xquery.parser.Variable;
34
35 public class HintTree extends Object JavaDoc {
36     private static final String JavaDoc RCSRevision = "$Revision: 1.2 $";
37     private static final String JavaDoc RCSName = "$Name: $";
38     
39     public static final byte NO_SIDE = 0;
40     public static final byte LEFT_SIDE = 1;
41     public static final byte RIGHT_SIDE = 2;
42     public static final byte NO_TYPE = 0;
43     public static final byte NESTED_TYPE = 1;
44     public static final byte JOIN_TYPE = 2;
45     public static final byte MERGE_TYPE = 3;
46     public static final byte CARTESIAN_PRODUCT_TYPE = 4;
47     public static final byte NESTED_LOOP_TYPE = 5;
48     
49     // can be null
50
protected Object JavaDoc left = null;
51     protected Object JavaDoc right = null;
52     protected byte type = NO_TYPE;
53     protected byte side = NO_SIDE;
54     protected byte outertype = NO_TYPE;
55     protected ArrayList JavaDoc varList = null;
56
57     // #############################################################################
58
// VISITOR STUFF
59
// #############################################################################
60

61     // #############################################################################
62
// CONSTRUCTOR STUFF
63
// #############################################################################
64

65     public HintTree(byte type, byte side, Object JavaDoc left, Object JavaDoc right) {
66         setType(type);
67         setSide(side);
68         setLeft(left);
69         setRight(right);
70     }
71     
72     // #############################################################################
73
// ATTRIBUTE ACCESS STUFF
74
// #############################################################################
75

76     public byte getType() {
77         return type;
78     }
79     
80     public byte getOuterType() {
81         return outertype;
82     }
83
84     public byte getSide() {
85         return side;
86     }
87     
88     public Object JavaDoc getLeftHint() {
89         return left;
90     }
91
92     public Object JavaDoc getRightHint() {
93         return right;
94     }
95
96     public void setType(byte type) {
97         this.type = type;
98     }
99     
100     public void setOuterType(byte outertype) {
101         this.outertype = outertype;
102     }
103
104     public void setSide(byte side) {
105         this.side = side;
106     }
107     
108     public void setLeft(Object JavaDoc left) {
109         this.left = left;
110         if (left == null) return;
111         if (left instanceof Variable)
112             this.addVarList((Variable)left);
113         else
114             this.addVarsList(((HintTree)left).getVarList());
115     }
116
117     public void setRight(Object JavaDoc right) {
118         this.right = right;
119         if (right == null) return;
120         if (right instanceof Variable)
121             this.addVarList((Variable)right);
122         else
123             this.addVarsList(((HintTree)right).getVarList());
124     }
125     
126     public void setVarList(ArrayList JavaDoc varList) {
127         this.varList = varList;
128     }
129     
130     public ArrayList JavaDoc getVarList() {
131         return this.varList;
132     }
133     
134     public boolean hasMerge() {
135         if (type == MERGE_TYPE)
136             return true;
137         boolean has = false;
138         if (left instanceof HintTree)
139             has = ((HintTree)left).hasMerge();
140         if (has)
141             return true;
142         if (right instanceof HintTree)
143             has = ((HintTree)right).hasMerge();
144         return has;
145     }
146
147     private void addVarList(Variable var) {
148         if (this.varList == null) this.varList = new ArrayList JavaDoc(1);
149         this.varList.add(var);
150     }
151
152     private void addVarsList(ArrayList JavaDoc vars) {
153         if (this.varList == null) this.varList = (ArrayList JavaDoc)vars.clone();
154         else this.varList.addAll(vars);
155     }
156     
157     // #############################################################################
158
// PRINT STUFF
159
// #############################################################################
160

161     public String JavaDoc toString() {
162         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
163         switch (type) {
164             case NESTED_TYPE : buf.append("nested"); break;
165             case JOIN_TYPE : buf.append("join"); break;
166             case MERGE_TYPE : buf.append("merge"); break;
167             case CARTESIAN_PRODUCT_TYPE : buf.append("cartesian-product"); break;
168             case NESTED_LOOP_TYPE : buf.append("nested-loop"); break;
169             default : buf.append("ERROR");
170         }
171         buf.append("(");
172         buf.append(left);
173         buf.append(" , ");
174         buf.append(right);
175         buf.append(")");
176         return buf.toString();
177     }
178     
179     // #############################################################################
180
// CLONE STUFF
181
// #############################################################################
182

183     
184 }
185
Popular Tags