1 22 23 28 29 package org.xquark.xquery.parser.hinttree; 30 31 import java.util.ArrayList ; 32 33 import org.xquark.xquery.parser.Variable; 34 35 public class HintTree extends Object { 36 private static final String RCSRevision = "$Revision: 1.2 $"; 37 private static final String 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 protected Object left = null; 51 protected Object right = null; 52 protected byte type = NO_TYPE; 53 protected byte side = NO_SIDE; 54 protected byte outertype = NO_TYPE; 55 protected ArrayList varList = null; 56 57 61 65 public HintTree(byte type, byte side, Object left, Object right) { 66 setType(type); 67 setSide(side); 68 setLeft(left); 69 setRight(right); 70 } 71 72 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 getLeftHint() { 89 return left; 90 } 91 92 public Object 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 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 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 varList) { 127 this.varList = varList; 128 } 129 130 public ArrayList 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 (1); 149 this.varList.add(var); 150 } 151 152 private void addVarsList(ArrayList vars) { 153 if (this.varList == null) this.varList = (ArrayList )vars.clone(); 154 else this.varList.addAll(vars); 155 } 156 157 161 public String toString() { 162 StringBuffer buf = new StringBuffer (); 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 183 184 } 185 | Popular Tags |