1 15 package org.josql.expressions; 16 17 import org.josql.Query; 18 import org.josql.QueryExecutionException; 19 20 import org.josql.internal.Utilities; 21 22 32 public class EqualsExpression extends BinaryExpression 33 { 34 35 private boolean not = false; 36 37 public boolean ignoreCase = false; 38 39 public void setIgnoreCase (boolean v) 40 { 41 42 this.ignoreCase = v; 43 44 } 45 46 public boolean isIgnoreCase () 47 { 48 49 return this.ignoreCase; 50 51 } 52 53 public boolean isNot () 54 { 55 56 return this.not; 57 58 } 59 60 public void setNot (boolean v) 61 { 62 63 this.not = v; 64 65 } 66 67 76 public boolean isTrue (Object o, 77 Query q) 78 throws QueryExecutionException 79 { 80 81 Object l = null; 83 84 try 85 { 86 87 l = this.left.getValue (o, 88 q); 89 90 } catch (Exception e) { 91 92 throw new QueryExecutionException ("Unable to get value for LHS of expression: " + 93 this, 94 e); 95 96 } 97 98 Object r = null; 99 100 try 101 { 102 103 r = this.right.getValue (o, 104 q); 105 106 } catch (Exception e) { 107 108 throw new QueryExecutionException ("Unable to get value for RHS of expression: " + 109 this, 110 e); 111 112 } 113 114 if ((l == null) 115 && 116 (r == null) 117 ) 118 { 119 120 if (this.not) 122 { 123 124 return false; 125 126 } 127 128 return true; 129 130 } 131 132 if ((l == null) 133 || 134 (r == null) 135 ) 136 { 137 138 if (this.not) 139 { 140 141 return true; 142 143 } 144 145 return false; 147 148 } 149 150 return Utilities.matches (l, 152 r, 153 this.ignoreCase, 154 4, 155 this.not); 156 157 335 336 } 337 338 344 public String toString () 345 { 346 347 String pred = "="; 348 349 if (this.not) 350 { 351 352 pred = "!="; 353 354 } 355 356 if (this.ignoreCase) 357 { 358 359 pred = "$" + pred; 360 361 } 362 363 if (this.isBracketed ()) 364 { 365 366 return "(" + this.left.toString () + " " + pred + " " + this.right.toString () + ")"; 367 368 } 369 370 return this.left.toString () + " " + pred + " " + this.right.toString (); 371 372 } 373 374 } 375 | Popular Tags |