← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19614: ExpressionUtils, minor

 

------------------------------------------------------------
revno: 19614
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-07-10 13:43:34 +0200
message:
  ExpressionUtils, minor
modified:
  dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java	2015-07-10 11:32:13 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/math/ExpressionFunctions.java	2015-07-10 11:43:34 +0000
@@ -35,33 +35,33 @@
     /**
      * Function which will return zero if the argument is a negative number.
      * 
-     * @param value the value.
+     * @param value the value, must be a number.
      * @return a Double.
      */
-    public static Double zing( String value )
+    public static Double zing( Number value )
     {
         if ( value == null )
         {
             throw new IllegalArgumentException( "Argument is null: " + value );
         }
         
-        return Math.max( 0d, Double.valueOf( value ) );
+        return Math.max( 0d, value.doubleValue() );
     }
 
     /**
      * Function which will return one if the argument is zero or a positive 
      * number, and zero if not.
      * 
-     * @param value the value.
+     * @param value the value, must be a number.
      * @return a Double.
      */
-    public static Double oizp( String value )
+    public static Double oizp( Number value )
     {
         if ( value == null )
         {
             throw new IllegalArgumentException( "Argument is null: " + value );
         }
         
-        return ( Double.valueOf( value ) >= 0d ) ? 1d : 0d;
+        return ( value.doubleValue() >= 0d ) ? 1d : 0d;
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java	2015-07-10 11:32:13 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java	2015-07-10 11:43:34 +0000
@@ -52,12 +52,12 @@
         assertEquals( 3.45, ExpressionUtils.evaluateToDouble( "3.45", null ), DELTA );
         assertEquals( 5d, ExpressionUtils.evaluateToDouble( "2 + 3", null ), DELTA );
         assertEquals( 15.6, ExpressionUtils.evaluateToDouble( "12.4 + 3.2", null ), DELTA );        
-        assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zing('3')", null ), DELTA );        
-        assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zing('-3') + 2.0", null ), DELTA );
-        assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing('-1') + 4 + d2:zing('-2')", null ), DELTA );
-        assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:oizp('-4')", null ), DELTA );
-        assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp('0')", null ), DELTA );
-        assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:oizp('-4') + d2:oizp('0') + d2:oizp('3.0')", null ), DELTA );
+        assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zing(3)", null ), DELTA );        
+        assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zing(-3) + 2.0", null ), DELTA );
+        assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(-1) + 4 + d2:zing(-2)", null ), DELTA );
+        assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4)", null ), DELTA );
+        assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp(0)", null ), DELTA );
+        assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4) + d2:oizp(0) + d2:oizp(3.0)", null ), DELTA );
     }
 
     @Test
@@ -65,8 +65,8 @@
     {
         Map<String, Object> vars = new HashMap<String, Object>();
         
-        vars.put( "v1", "4" );
-        vars.put( "v2", "-5" );
+        vars.put( "v1", 4d );
+        vars.put( "v2", -5d );
         
         assertEquals( 7d, ExpressionUtils.evaluateToDouble( "v1 + 3", vars ), DELTA );
         assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(v1)", vars ), DELTA );