← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20449: ExpressionUtils. Adjusted numeric regex.

 

------------------------------------------------------------
revno: 20449
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-10-01 17:36:32 +0200
message:
  ExpressionUtils. Adjusted numeric regex.
modified:
  dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java
  dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/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/util/ExpressionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java	2015-09-15 16:57:32 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/ExpressionUtils.java	2015-10-01 15:36:32 +0000
@@ -52,7 +52,7 @@
     private static final String IGNORED_KEYWORDS_REGEX = 
         "SUM|sum|AVERAGE|average|COUNT|count|STDDEV|stddev|VARIANCE|variance|MIN|min|MAX|max|NONE|none";
 
-    private static final Pattern NUMERIC_PATTERN = Pattern.compile( "^(-?0|-?[1-9]\\d*)(\\.\\d+)?(E(-)?\\d+)?$" );
+    private static final Pattern NUMERIC_PATTERN = Pattern.compile( "^(-?0|-?[1-9]\\d*)(\\.\\d+)?$" );
     
     static
     {

=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java	2015-09-25 12:58:13 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java	2015-10-01 15:36:32 +0000
@@ -205,4 +205,46 @@
         assertFalse( ExpressionUtils.isValid( "'goat' == goat", null ) );
         assertFalse( ExpressionUtils.isValid( "aver(2+1)", null ) );
     }
+
+    @Test
+    public void testIsNumeric()
+    {
+        assertTrue( ExpressionUtils.isNumeric( "123" ) );
+        assertTrue( ExpressionUtils.isNumeric( "0" ) );
+        assertTrue( ExpressionUtils.isNumeric( "1.2" ) );
+        assertTrue( ExpressionUtils.isNumeric( "12.34" ) );
+        assertTrue( ExpressionUtils.isNumeric( "0.0" ) );
+        assertTrue( ExpressionUtils.isNumeric( "1.234" ) );
+        assertTrue( ExpressionUtils.isNumeric( "-1234" ) );
+        assertTrue( ExpressionUtils.isNumeric( "-12.34" ) );
+        assertTrue( ExpressionUtils.isNumeric( "-0.34" ) );
+        assertTrue( ExpressionUtils.isNumeric( "6.34" ) );
+        assertTrue( ExpressionUtils.isNumeric( "3.34" ) );
+        assertTrue( ExpressionUtils.isNumeric( "2.43" ) );
+
+        assertFalse( ExpressionUtils.isNumeric( "Hey" ) );
+        assertFalse( ExpressionUtils.isNumeric( "45 Perinatal Condition" ) );
+        assertFalse( ExpressionUtils.isNumeric( "Long street 2" ) );
+        assertFalse( ExpressionUtils.isNumeric( "1.2f" ) );
+        assertFalse( ExpressionUtils.isNumeric( "1 234" ) );
+        assertFalse( ExpressionUtils.isNumeric( "." ) );
+        assertFalse( ExpressionUtils.isNumeric( "1." ) );
+        assertFalse( ExpressionUtils.isNumeric( ".1" ) );
+        assertFalse( ExpressionUtils.isNumeric( "" ) );
+        assertFalse( ExpressionUtils.isNumeric( " " ) );
+        assertFalse( ExpressionUtils.isNumeric( "+1234  " ) );
+        assertFalse( ExpressionUtils.isNumeric( "1234  " ) );
+        assertFalse( ExpressionUtils.isNumeric( "  1234" ) );
+        assertFalse( ExpressionUtils.isNumeric( "1,234" ) );
+        assertFalse( ExpressionUtils.isNumeric( "0,1" ) );
+        assertFalse( ExpressionUtils.isNumeric( "0," ) );
+        assertFalse( ExpressionUtils.isNumeric( "0." ) );
+        assertFalse( ExpressionUtils.isNumeric( "01" ) );
+        assertFalse( ExpressionUtils.isNumeric( "001" ) );
+        assertFalse( ExpressionUtils.isNumeric( "00.23" ) );
+        assertFalse( ExpressionUtils.isNumeric( "01.23" ) );
+        assertFalse( ExpressionUtils.isNumeric( "4.23E" ) );
+        assertFalse( ExpressionUtils.isNumeric( "4.23Ef" ) );
+        assertFalse( ExpressionUtils.isNumeric( "E5" ) );
+    }
 }