1 package org.apache.ojb.jdo.jdoql; 2 3 17 18 23 public class BinaryExpression extends Expression 24 { 25 public static final int OPERATOR_MULTIPLY = 0; 26 public static final int OPERATOR_DIVIDE = 1; 27 public static final int OPERATOR_PLUS = 2; 28 public static final int OPERATOR_MINUS = 3; 29 public static final int OPERATOR_LOWER = 4; 30 public static final int OPERATOR_GREATER = 5; 31 public static final int OPERATOR_LOWER_OR_EQUAL = 6; 32 public static final int OPERATOR_GREATER_OR_EQUAL = 7; 33 public static final int OPERATOR_EQUAL = 8; 34 public static final int OPERATOR_NOT_EQUAL = 9; 35 public static final int OPERATOR_BITWISE_AND = 10; 36 public static final int OPERATOR_BITWISE_XOR = 11; 37 public static final int OPERATOR_BITWISE_OR = 12; 38 public static final int OPERATOR_AND = 13; 39 public static final int OPERATOR_OR = 14; 40 41 42 private Expression _left; 43 44 private int _operator; 45 46 private Expression _right; 47 48 private Class _type; 49 50 57 public BinaryExpression(Expression left, int operator, Expression right) 58 { 59 _left = left; 60 _operator = operator; 61 _right = right; 62 } 63 64 69 public Expression getLeftSide() 70 { 71 return _left; 72 } 73 74 79 public int getOperator() 80 { 81 return _operator; 82 } 83 84 89 public Expression getRightSide() 90 { 91 return _right; 92 } 93 94 97 public void replaceChild(Expression oldChild, Expression newChild) 98 { 99 if (oldChild == _left) 100 { 101 _left.setParent(null); 102 _left = newChild; 103 _left.setParent(this); 104 } 105 else if (oldChild == _right) 106 { 107 _right.setParent(null); 108 _right = newChild; 109 _right.setParent(this); 110 } 111 } 112 113 116 public void accept(Visitor visitor) 117 { 118 visitor.visit(this); 119 } 120 121 124 public String toString() 125 { 126 StringBuffer result = new StringBuffer (); 127 128 result.append("("); 129 result.append(_left.toString()); 130 result.append(" "); 131 switch (_operator) 132 { 133 case OPERATOR_MULTIPLY : 134 result.append("* "); 135 break; 136 case OPERATOR_DIVIDE : 137 result.append("/ "); 138 break; 139 case OPERATOR_PLUS : 140 result.append("+ "); 141 break; 142 case OPERATOR_MINUS : 143 result.append("- "); 144 break; 145 case OPERATOR_LOWER : 146 result.append("< "); 147 break; 148 case OPERATOR_GREATER : 149 result.append("> "); 150 break; 151 case OPERATOR_LOWER_OR_EQUAL : 152 result.append("<= "); 153 break; 154 case OPERATOR_GREATER_OR_EQUAL : 155 result.append(">= "); 156 break; 157 case OPERATOR_EQUAL : 158 result.append("== "); 159 break; 160 case OPERATOR_NOT_EQUAL : 161 result.append("!= "); 162 break; 163 case OPERATOR_BITWISE_AND : 164 result.append("& "); 165 break; 166 case OPERATOR_BITWISE_XOR : 167 result.append("^ "); 168 break; 169 case OPERATOR_BITWISE_OR : 170 result.append("| "); 171 break; 172 case OPERATOR_AND : 173 result.append("&& "); 174 break; 175 case OPERATOR_OR : 176 result.append("|| "); 177 break; 178 } 179 result.append(_right.toString()); 180 result.append(")"); 181 return result.toString(); 182 } 183 184 189 public void setType(Class type) 190 { 191 _type = type; 192 } 193 194 197 public Class getType() 198 { 199 return _type; 200 } 201 } 202 | Popular Tags |