geirm 2003/12/17 04:49:35 Modified: jexl/src/java/org/apache/commons/jexl/parser ASTAddNode.java Log: Patch from Robert McIntosh to add string contat via "+". Not totally sure if we want it this way... but lets see what people thingk. Also fixed problem that should have been there when one arg to an + is null. Revision Changes Path 1.4 +26 -11 jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTAddNode.java Index: ASTAddNode.java =================================================================== RCS file: /home/cvs/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTAddNode.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ASTAddNode.java 9 Oct 2003 21:28:55 -0000 1.3 +++ ASTAddNode.java 17 Dec 2003 12:49:35 -0000 1.4 @@ -98,7 +98,7 @@ * if anything is float, double or string with ( "." | "E" | "e") * coerce all to doubles and do it */ - if ( left instanceof Float || left instanceof Double + if (left instanceof Float || left instanceof Double || right instanceof Float || right instanceof Double || ( left instanceof String && ( ((String) left).indexOf(".") != -1 || @@ -108,23 +108,38 @@ || ( right instanceof String && ( ((String) right).indexOf(".") != -1 || ((String) right).indexOf("e") != -1 || - ((String) right).indexOf("E") != -1 ) + ((String) right).indexOf("E") != -1) ) ) { - Double l = Coercion.coerceDouble(left); - Double r = Coercion.coerceDouble(right); - return new Double( l.doubleValue() + r.doubleValue() ); + /* + * in the event that either is null and not both, then just make the + * null a 0 + */ + + Double l = left == null ? new Double(0) : Coercion.coerceDouble(left); + Double r = right == null? new Double(0) : Coercion.coerceDouble(right); + + return new Double(l.doubleValue() + r.doubleValue()); } /* - * otherwise to longs with thee! + * attempt to use Longs */ + try + { + Long l = left == null ? new Long(0) : Coercion.coerceLong(left); + Long r = right == null ? new Long(0) : Coercion.coerceLong(right); - Long l = Coercion.coerceLong(left); - Long r = Coercion.coerceLong(right); - - return new Long(l.longValue() + r.longValue()); + return new Long(l.longValue() + r.longValue()); + } + catch( java.lang.NumberFormatException nfe ) + { + /* + * Well, use strings! + */ + return left.toString().concat(right.toString()); + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]