← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2820: Fixed the numeric method fix

 

------------------------------------------------------------
revno: 2820
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-02-04 22:33:00 +0100
message:
  Fixed the numeric method fix
modified:
  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-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	2011-02-04 19:16:38 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java	2011-02-04 21:33:00 +0000
@@ -45,7 +45,7 @@
     
     private static final double TOLERANCE = 0.01; 
     
-    private static final Pattern NUMERIC_PATTERN = Pattern.compile( "^[ \t]*[0-9]*[.]?[0-9]*[ \t]*$" );
+    private static final Pattern NUMERIC_PATTERN = Pattern.compile( "^[ \\t]*[\\.]?[0-9]+[ \\t]*$|^[ \\t]*[0-9]+[\\.][0-9]+[ \\t]*$" );
 
     /**
      * Validates whether an expression is true or false.
@@ -187,7 +187,7 @@
      */
     public static boolean isNumeric( String value )
     {
-        return value != null && !value.trim().isEmpty() && NUMERIC_PATTERN.matcher( value ).matches();
+        return value != null && NUMERIC_PATTERN.matcher( value ).matches();
     }
     
     /**

=== 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	2011-02-04 19:16:38 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java	2011-02-04 21:33:00 +0000
@@ -89,6 +89,7 @@
         assertTrue( MathUtils.isNumeric( "1.2" ) );
         assertTrue( MathUtils.isNumeric( "12.34" ) );
         assertTrue( MathUtils.isNumeric( "0.0" ) );
+        assertTrue( MathUtils.isNumeric( ".1" ) );
         assertTrue( MathUtils.isNumeric( "1.234" ) );
         assertTrue( MathUtils.isNumeric( "1234  " ) );
         assertTrue( MathUtils.isNumeric( "  1234" ) );
@@ -98,6 +99,8 @@
         assertFalse( MathUtils.isNumeric( "Long street 2" ) );
         assertFalse( MathUtils.isNumeric( "1.2f" ) );
         assertFalse( MathUtils.isNumeric( "1 234" ) );
+        assertFalse( MathUtils.isNumeric( "." ) );
+        assertFalse( MathUtils.isNumeric( "1." ) );
         assertFalse( MathUtils.isNumeric( "" ) );
         assertFalse( MathUtils.isNumeric( " " ) );
         assertFalse( MathUtils.isNumeric( null ) );