1 15 package org.josql.expressions; 16 17 import org.josql.Query; 18 import org.josql.QueryExecutionException; 19 20 31 public class AndOrExpression extends BinaryExpression 32 { 33 34 private boolean and = false; 35 36 public boolean isAnd () 37 { 38 39 return this.and; 40 41 } 42 43 public void setAnd (boolean v) 44 { 45 46 this.and = v; 47 48 } 49 50 115 public boolean isTrue (Object o, 116 Query q) 117 throws QueryExecutionException 118 { 119 120 boolean l = this.left.isTrue (o, 122 q); 123 124 if (this.and) 126 { 127 128 if (!l) 129 { 130 131 return false; 132 133 } 134 135 boolean r = this.right.isTrue (o, 136 q); 137 138 return l && r; 139 140 } 141 142 if (l) 143 { 144 145 return true; 146 147 } 148 149 boolean r = this.right.isTrue (o, 150 q); 151 152 return r; 153 154 } 155 156 162 public String toString () 163 { 164 165 String pred = " OR "; 166 167 if (this.and) 168 { 169 170 pred = " AND "; 171 172 } 173 174 if (this.isBracketed ()) 175 { 176 177 return "(" + this.left.toString () + pred + this.right.toString () + ")"; 178 179 } 180 181 return this.left.toString () + pred + this.right.toString (); 182 183 } 184 185 } 186 | Popular Tags |