1 29 30 package com.caucho.el; 31 32 import com.caucho.vfs.WriteStream; 33 34 import javax.el.ELContext; 35 import javax.el.ELException; 36 import java.io.IOException ; 37 import java.math.BigDecimal ; 38 import java.math.BigInteger ; 39 40 43 public class EqExpr extends AbstractBooleanExpr { 44 private final Expr _left; 45 private final Expr _right; 46 47 54 public EqExpr(Expr left, Expr right) 55 { 56 _left = left; 57 _right = right; 58 } 59 60 63 @Override 64 public boolean isConstant() 65 { 66 return _left.isConstant() && _right.isConstant(); 67 } 68 69 74 @Override 75 public boolean evalBoolean(ELContext env) 76 throws ELException 77 { 78 Object aObj = _left.getValue(env); 79 Object bObj = _right.getValue(env); 80 81 if (aObj == bObj) 82 return true; 83 84 if (aObj == null || bObj == null) 85 return false; 86 87 Class aType = aObj.getClass(); 88 Class bType = bObj.getClass(); 89 90 if (aObj instanceof BigDecimal || bObj instanceof BigDecimal ) { 91 BigDecimal a = toBigDecimal(aObj, env); 92 BigDecimal b = toBigDecimal(bObj, env); 93 94 return a.equals(b); 95 } 96 97 if (aType == Double .class || aType == Float .class || 98 bType == Double .class || bType == Float .class) { 99 double a = toDouble(aObj, env); 100 double b = toDouble(bObj, env); 101 102 return a == b; 103 } 104 105 if (aType == BigInteger .class || bType == BigInteger .class) { 106 BigInteger a = toBigInteger(aObj, env); 107 BigInteger b = toBigInteger(bObj, env); 108 109 return a.equals(b); 110 } 111 112 if (aObj instanceof Number || bObj instanceof Number ) { 113 long a = toLong(aObj, env); 114 long b = toLong(bObj, env); 115 116 return a == b; 117 } 118 119 if (aType == Boolean .class || bType == Boolean .class) { 120 boolean a = toBoolean(aObj, env); 121 boolean b = toBoolean(bObj, env); 122 123 return a == b; 124 } 125 126 128 if (aObj instanceof String || bObj instanceof String ) { 129 String a = toString(aObj, env); 130 String b = toString(bObj, env); 131 132 return a.equals(b); 133 } 134 135 return aObj.equals(bObj); 136 } 137 138 141 @Override 142 public void printCreate(WriteStream os) 143 throws IOException 144 { 145 os.print("new com.caucho.el.EqExpr("); 146 _left.printCreate(os); 147 os.print(", "); 148 _right.printCreate(os); 149 os.print(")"); 150 } 151 152 155 public boolean equals(Object o) 156 { 157 if (! (o instanceof EqExpr)) 158 return false; 159 160 EqExpr expr = (EqExpr) o; 161 162 return (_left.equals(expr._left) && 163 _right.equals(expr._right)); 164 } 165 166 169 public String toString() 170 { 171 return "(" + _left + " eq " + _right + ")"; 172 } 173 } 174 | Popular Tags |