← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19054: Added MathUtils.expressionIsTrue(String)

 

------------------------------------------------------------
revno: 19054
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-04-29 12:29:05 +0200
message:
  Added MathUtils.expressionIsTrue(String)
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisService.java	2015-04-29 10:29:05 +0000
@@ -81,6 +81,7 @@
         loop : for ( DataElement dataElement : dataElements )
         {
             // TODO filter periods with data element period type
+            // TODO use _orgunitstructure to find org units instead of in clause
             
             if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
             {

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2015-04-23 17:11:18 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2015-04-29 10:29:05 +0000
@@ -68,17 +68,28 @@
     private static final Pattern ZERO_PATTERN = Pattern.compile( "^0(\\.0*)?$" );
 
     /**
-     * Validates whether an expression is true or false.
+     * Evaluates whether an expression is true or false.
      * 
      * @param leftSide The left side of the expression.
      * @param operator The expression operator.
      * @param rightSide The right side of the expression.
-     * @return True if the expressio is true, fals otherwise.
+     * @return True if the expression is true, false otherwise.
      */
     public static boolean expressionIsTrue( double leftSide, Operator operator, double rightSide )
     {
         final String expression = leftSide + operator.getMathematicalOperator() + rightSide;
         
+        return expressionIsTrue( expression );
+    }
+
+    /**
+     * Evaluates whether an expression is true or false.
+     * 
+     * @param expression the expression to evaluate.
+     * @return True if the expression is true, false otherwise.
+     */
+    public static boolean expressionIsTrue( String expression )
+    {
         final JEP parser = getJep();
         parser.parseExpression( expression );
         

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2015-04-22 15:07:43 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2015-04-29 10:29:05 +0000
@@ -52,7 +52,7 @@
     private static final double DELTA = 0.01;
     
     @Test
-    public void testExpressionIsTrue()
+    public void testExpressionIsTrueLeftRight()
     {
         assertFalse( expressionIsTrue( 20.0, equal_to, 10.0 ) );
         assertTrue( expressionIsTrue( 20.0, not_equal_to, 10.0 ) );
@@ -62,6 +62,18 @@
         assertTrue( expressionIsTrue( 40.0, less_than_or_equal_to, 50.0 ) );
         assertFalse( expressionIsTrue( 0.0, greater_than_or_equal_to, 20.0 ) );
     }
+
+    @Test
+    public void testExpressionIsTrue()
+    {
+        assertFalse( expressionIsTrue( "20.1 < 10.0" ) );
+        assertFalse( expressionIsTrue( "1 == 0" ) );
+        assertFalse( expressionIsTrue( "5 > 6" ) );
+
+        assertTrue( expressionIsTrue( "20.1 > 10.0" ) );
+        assertTrue( expressionIsTrue( "2 == 2" ) );
+        assertTrue( expressionIsTrue( "5 < 6" ) );
+    }
     
     @Test
     public void testGetMin()