Author: henrib
Date: Fri Aug 12 13:28:34 2011
New Revision: 1157099
URL: http://svn.apache.org/viewvc?rev=1157099&view=rev
Log:
Fixed arithmetic that was not using the proper math scale when using
JexlThreadedArithmetic
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java?rev=1157099&r1=1157098&r2=1157099&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
Fri Aug 12 13:28:34 2011
@@ -111,8 +111,9 @@ public class JexlArithmetic {
* @return the rounded big decimal
*/
public BigDecimal roundBigDecimal(final BigDecimal number) {
- if (mathScale >= 0) {
- return number.setScale(getMathScale(),
getMathContext().getRoundingMode());
+ int mscale = getMathScale();
+ if (mscale >= 0) {
+ return number.setScale(mscale, getMathContext().getRoundingMode());
} else {
return number;
}
@@ -594,7 +595,9 @@ public class JexlArithmetic {
*/
return false;
} else if (left instanceof BigDecimal || right instanceof BigDecimal) {
- return toBigDecimal(left).compareTo(toBigDecimal(right)) == 0;
+ BigDecimal lhs = toBigDecimal(left);
+ BigDecimal rhs = toBigDecimal(right);
+ return lhs.compareTo(rhs) == 0;
} else if (left.getClass().equals(right.getClass())) {
return left.equals(right);
} else if (isFloatingPointType(left, right)) {
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1157099&r1=1157098&r2=1157099&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Fri Aug 12 13:28:34 2011
@@ -675,7 +675,7 @@ public class IssuesTest extends JexlTest
// will succeed with scale = 2
JexlThreadedArithmetic.setMathScale(2);
- assertFalse((Boolean) exp1.evaluate(ctx));
+ assertTrue((Boolean) exp1.evaluate(ctx));
}
public void test112() throws Exception {
@@ -697,4 +697,25 @@ public class IssuesTest extends JexlTest
Object result = e.evaluate(ctx);
assertTrue((Boolean) result);
}
+
+ public void testStringIdentifier() throws Exception {
+ JexlEngine jexl = new JexlEngine();
+ Map<String, String> foo = new HashMap<String, String>();
+
+ JexlContext jc = new MapContext();
+ jc.set("foo", foo);
+ foo.put("q u u x", "456");
+ Expression e = jexl.createExpression("foo.\"q u u x\"");
+ Object result = e.evaluate(jc);
+ assertEquals("456", result);
+ e = jexl.createExpression("foo.'q u u x'");
+ result = e.evaluate(jc);
+ assertEquals("456", result);
+ Script s = jexl.createScript("foo.\"q u u x\"");
+ result = s.execute(jc);
+ assertEquals("456", result);
+ s = jexl.createScript("foo.'q u u x'");
+ result = s.execute(jc);
+ assertEquals("456", result);
+ }
}