You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2011/05/21 18:04:03 UTC
svn commit: r1125736 - in /commons/proper/jexl/trunk:
jexl2-compat/src/main/java/org/apache/commons/jexl/
jexl2-compat/src/main/java/org/apache/commons/jexl/context/
src/main/java/org/apache/commons/jexl2/ src/site/xdoc/
Author: henrib
Date: Sat May 21 16:04:02 2011
New Revision: 1125736
URL: http://svn.apache.org/viewvc?rev=1125736&view=rev
Log:
Removing unwarranted Netbeans conf
Modified:
commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ExpressionFactory.java
commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlContext.java
commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlHelper.java
commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ScriptFactory.java
commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/context/HashMapContext.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
commons/proper/jexl/trunk/src/site/xdoc/changes.xml
Modified: commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ExpressionFactory.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ExpressionFactory.java (original)
+++ commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ExpressionFactory.java Sat May 21 16:04:02 2011
@@ -41,8 +41,8 @@ import org.apache.commons.jexl2.JexlEngi
* that serves the same purpose with more control is recommended.
* </p>
* @since 1.0
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id: ExpressionFactory.java 884175 2009-11-25 16:23:41Z henrib $
+ *
+ * @version $Id$
* @deprecated Create a JexlEngine and use the createScript method on that instead.
*/
@Deprecated
Modified: commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlContext.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlContext.java (original)
+++ commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlContext.java Sat May 21 16:04:02 2011
@@ -22,8 +22,8 @@ import java.util.Map;
* Holds a Map of variables which are referenced in a JEXL expression.
*
* @since 1.0
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id: JexlContext.java 480412 2006-11-29 05:11:23Z bayard $
+ *
+ * @version $Id$
*/
public interface JexlContext {
/**
Modified: commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlHelper.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlHelper.java (original)
+++ commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/JexlHelper.java Sat May 21 16:04:02 2011
@@ -26,8 +26,8 @@ import org.apache.commons.jexl.context.H
* own application.
*
* @since 1.0
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id: JexlHelper.java 480412 2006-11-29 05:11:23Z bayard $
+ *
+ * @version $Id$
*/
public class JexlHelper {
/** singleton instance. */
Modified: commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ScriptFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ScriptFactory.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ScriptFactory.java (original)
+++ commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/ScriptFactory.java Sat May 21 16:04:02 2011
@@ -39,7 +39,7 @@ import org.apache.commons.jexl2.JexlEngi
* that serves the same purpose with more control is recommended.
* </p>
* @since 1.1
- * @version $Id: ScriptFactory.java 884175 2009-11-25 16:23:41Z henrib $
+ * @version $Id$
* @deprecated Create a JexlEngine and use the createScript method on that instead.
*/
@Deprecated
Modified: commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/context/HashMapContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/context/HashMapContext.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/context/HashMapContext.java (original)
+++ commons/proper/jexl/trunk/jexl2-compat/src/main/java/org/apache/commons/jexl/context/HashMapContext.java Sat May 21 16:04:02 2011
@@ -26,8 +26,8 @@ import java.util.Map;
* Implementation of JexlContext based on a HashMap.
*
* @since 1.0
- * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id: HashMapContext.java 706202 2008-10-20 10:28:25Z sebb $
+ *
+ * @version $Id$
*/
public class HashMapContext extends HashMap<String,Object> implements JexlContext {
/** serialization version id jdk13 generated. */
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=1125736&r1=1125735&r2=1125736&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 Sat May 21 16:04:02 2011
@@ -52,7 +52,7 @@ public class JexlArithmetic {
/** Long.MIN_VALUE as BigInteger. */
protected static final BigInteger BIGI_LONG_MIN_VALUE = BigInteger.valueOf(Long.MIN_VALUE);
/** Default BigDecimal scale. */
- protected static final int BIGD_SCALE = 5;
+ protected static final int BIGD_SCALE = -1;
/** Whether this JexlArithmetic instance behaves in strict or lenient mode. */
protected final boolean strict;
/** The big decimal math context. */
@@ -72,6 +72,7 @@ public class JexlArithmetic {
* Creates a JexlArithmetic.
* @param lenient whether this arithmetic is lenient or strict
* @param bigdContext the math context instance to use for +,-,/,*,% operations on big decimals.
+ * @param bigdScale the scale used for big decimals.
*/
public JexlArithmetic(boolean lenient, MathContext bigdContext, int bigdScale) {
this.strict = !lenient;
@@ -95,7 +96,7 @@ public class JexlArithmetic {
public MathContext getMathContext() {
return mathContext;
}
-
+
/**
* The BigDecimal scale used for comparison and coericion operations.
* @return the scale
@@ -103,14 +104,18 @@ public class JexlArithmetic {
public int getMathScale() {
return mathScale;
}
-
+
/**
* Ensure a big decimal is rounded by this arithmetic scale and rounding mode.
* @param number the big decimal to round
* @return the rounded big decimal
*/
public BigDecimal roundBigDecimal(final BigDecimal number) {
- return number.setScale(mathScale, mathContext.getRoundingMode());
+ if (mathScale >= 0) {
+ return number.setScale(mathScale, getMathContext().getRoundingMode());
+ } else {
+ return number;
+ }
}
/**
@@ -221,10 +226,10 @@ public class JexlArithmetic {
/**
* Given a BigDecimal, attempt to narrow it to an Integer or Long if it fits if
* one of the arguments is a numberable.
- * </p>
+ *
* @param lhs the left hand side operand that lead to the bigd result
* @param rhs the right hand side operand that lead to the bigd result
- * @param bigi the BigInteger to narrow
+ * @param bigd the BigDecimal to narrow
* @return an Integer or Long if narrowing is possible, the original BigInteger otherwise
*/
protected Number narrowBigDecimal(Object lhs, Object rhs, BigDecimal bigd) {
@@ -237,13 +242,13 @@ public class JexlArithmetic {
} else {
return Long.valueOf(l);
}
- } catch(ArithmeticException xa) {
+ } catch (ArithmeticException xa) {
// ignore, no exact value possible
}
}
return bigd;
}
-
+
/**
* Given an array of objects, attempt to type it more strictly.
* <ul>
@@ -357,7 +362,7 @@ public class JexlArithmetic {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.add(r, mathContext);
+ BigDecimal result = l.add(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
@@ -398,7 +403,7 @@ public class JexlArithmetic {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.divide(r, mathContext);
+ BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
@@ -435,7 +440,7 @@ public class JexlArithmetic {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
- BigDecimal remainder = l.remainder(r, mathContext);
+ BigDecimal remainder = l.remainder(r, getMathContext());
return narrowBigDecimal(left, right, remainder);
}
@@ -468,7 +473,7 @@ public class JexlArithmetic {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.multiply(r, mathContext);
+ BigDecimal result = l.multiply(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
@@ -501,7 +506,7 @@ public class JexlArithmetic {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.subtract(r, mathContext);
+ BigDecimal result = l.subtract(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
@@ -769,9 +774,9 @@ public class JexlArithmetic {
if ("".equals(string)) {
return BigDecimal.valueOf(0);
}
- return roundBigDecimal(new BigDecimal(string, mathContext));
+ return roundBigDecimal(new BigDecimal(string, getMathContext()));
} else if (val instanceof Number) {
- return roundBigDecimal(new BigDecimal(val.toString(), mathContext));
+ return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
} else if (val instanceof Character) {
int i = ((Character) val).charValue();
return new BigDecimal(i);
@@ -852,6 +857,18 @@ public class JexlArithmetic {
// if it's bigger than a double it can't be narrowed
if (bigd.compareTo(BIGD_DOUBLE_MAX_VALUE) > 0) {
return original;
+ } else {
+ try {
+ long l = bigd.longValueExact();
+ // coerce to int when possible (int being so often used in method parms)
+ if (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
+ return Integer.valueOf((int) l);
+ } else {
+ return Long.valueOf(l);
+ }
+ } catch (ArithmeticException xa) {
+ // ignore, no exact value possible
+ }
}
}
if (original instanceof Double || original instanceof Float || original instanceof BigDecimal) {
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java Sat May 21 16:04:02 2011
@@ -48,13 +48,14 @@ public class JexlThreadedArithmetic exte
* Creates a JexlThreadedArithmetic.
* @param lenient whether this arithmetic is lenient or strict
* @param bigdContext the math context instance to use for +,-,/,*,% operations on big decimals.
+ * @param bigdScale the scale used for big decimals.
*/
public JexlThreadedArithmetic(boolean lenient, MathContext bigdContext, int bigdScale) {
super(lenient, bigdContext, bigdScale);
}
/** Whether this JexlArithmetic instance behaves in strict or lenient mode for this thread. */
- static final ThreadLocal<Features> features = new ThreadLocal<Features>() {
+ static final ThreadLocal<Features> FEATURES = new ThreadLocal<Features>() {
@Override
protected synchronized Features initialValue() {
return new Features();
@@ -73,7 +74,7 @@ public class JexlThreadedArithmetic exte
* @param flag true means no JexlException will occur, false allows them, null reverts to default behavior
*/
public static void setLenient(Boolean flag) {
- features.get().lenient = flag == null? null : flag;
+ FEATURES.get().lenient = flag == null? null : flag;
}
/**
@@ -82,7 +83,7 @@ public class JexlThreadedArithmetic exte
* @param scale the scale
*/
public static void setMathScale(Integer scale) {
- features.get().mathScale = scale;
+ FEATURES.get().mathScale = scale;
}
/**
@@ -91,25 +92,25 @@ public class JexlThreadedArithmetic exte
* @param mc the math context
*/
public static void setMathContext(MathContext mc) {
- features.get().mathContext = mc;
+ FEATURES.get().mathContext = mc;
}
/** {@inheritDoc} */
@Override
public boolean isLenient() {
- Boolean lenient = features.get().lenient;
+ Boolean lenient = FEATURES.get().lenient;
return lenient == null ? super.isLenient() : lenient.booleanValue();
}
@Override
public int getMathScale() {
- Integer scale = features.get().mathScale;
+ Integer scale = FEATURES.get().mathScale;
return scale == null ? super.getMathScale() : scale.intValue();
}
@Override
public MathContext getMathContext() {
- MathContext mc = features.get().mathContext;
+ MathContext mc = FEATURES.get().mathContext;
return mc == null? super.getMathContext() : mc;
}
}
Modified: commons/proper/jexl/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/changes.xml?rev=1125736&r1=1125735&r2=1125736&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/jexl/trunk/src/site/xdoc/changes.xml Sat May 21 16:04:02 2011
@@ -26,20 +26,27 @@
</properties>
<body>
<release version="2.0.2" date="unreleased">
+ <action dev="henrib" type="add">
+ Added ObjectContext that wraps an object as JexlContext and added JexlContext as source to solve
+ top-level namespace functions.
+ </action>
+ <action dev="henrib" type="fix" issue="JEXL-111" due-to="freish">
+ expression execute error depending on numeric type
+ </action>
<action dev="henrib" type="add" issue="JEXL-83" due-to="sebb">
- Make JexlArithmetic immutable (and threadsafe)
+ Make JexlArithmetic immutable (and threadsafe); also added a mutable JexlThreadedArithmetic.
</action>
- <action dev="henrib" type="add" issue="JEXL-108" due-to="Cristian Lorenzetto">
+ <action dev="henrib" type="fix" issue="JEXL-108" due-to="Cristian Lorenzetto">
Parsing error if i define a empty literal array/map
</action>
- <action dev="henrib" type="add" issue="JEXL-107" due-to="henrib">
+ <action dev="henrib" type="fix" issue="JEXL-107" due-to="henrib">
Literals and parenthesized expressions can not be used as references
</action>
- <action dev="henrib" type="add" issue="JEXL-106" due-to="Michal Sabol">
+ <action dev="henrib" type="fix" issue="JEXL-106" due-to="Michal Sabol">
When divide two BigDecimal values in an expression it results in java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
</action>
<action dev="henrib" type="add" issue="JEXL-105" due-to="Cary Thompson">Array literals are considered constant even when they are not.</action>
- <action dev="henrib" type="add" issue="JEXL-104" due-to="Andreas Haufler">NPE in JexlArithmetic when an Array-Expression containing a null is used.</action>
+ <action dev="henrib" type="fix" issue="JEXL-104" due-to="Andreas Haufler">NPE in JexlArithmetic when an Array-Expression containing a null is used.</action>
<action dev="henrib" type="add" issue="JEXL-102" due-to="sebb">Add "jexl2" as a supported name</action>
<action dev="henrib" type="add" issue="JEXL-101" due-to="Tobias Shulte">
Vararg methods where the first argument is no vararg can not be called with only the fixed parameters given