commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1609898 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/math/NumberUtils.java test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Date Sat, 12 Jul 2014 09:48:14 GMT
Author: britter
Date: Sat Jul 12 09:48:13 2014
New Revision: 1609898

URL: http://svn.apache.org/r1609898
Log:
LANG-1016: NumberUtils#isParsable method(s). Apply Juan PabloSantos Rodríguez patch for handling
negative numbers.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java?rev=1609898&r1=1609897&r2=1609898&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
Sat Jul 12 09:48:13 2014
@@ -1488,7 +1488,11 @@ public class NumberUtils {
         if( StringUtils.endsWith( str, "." ) ) {
             return false;
         }
-        return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
+        if( StringUtils.startsWith( str, "-" ) ) {
+            return isDigits( StringUtils.replaceOnce( StringUtils.substring( str, 1 ), ".",
StringUtils.EMPTY ) );
+        } else {
+            return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
+        }
     }
 
 }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=1609898&r1=1609897&r2=1609898&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
Sat Jul 12 09:48:13 2014
@@ -1268,7 +1268,12 @@ public class NumberUtilsTest {
         assertFalse( NumberUtils.isParsable("64L") );
         assertTrue( NumberUtils.isParsable("64.2") );
         assertTrue( NumberUtils.isParsable("64") );
-        assertTrue(NumberUtils.isParsable("018"));
+        assertTrue( NumberUtils.isParsable("018") );
+        assertTrue( NumberUtils.isParsable(".18") );
+        assertTrue( NumberUtils.isParsable("-65") );
+        assertTrue( NumberUtils.isParsable("-018") );
+        assertTrue( NumberUtils.isParsable("-018.2") );
+        assertTrue( NumberUtils.isParsable("-.236") );
     }
 
     private boolean checkCreateNumber(final String val) {



Mime
View raw message