commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r893088 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/math/NumberUtils.java test/org/apache/commons/lang3/math/NumberUtilsTest.java
Date Tue, 22 Dec 2009 06:53:03 GMT
Author: bayard
Date: Tue Dec 22 06:52:42 2009
New Revision: 893088

URL: http://svn.apache.org/viewvc?rev=893088&view=rev
Log:
isNumber(String) and createNumber(String) both modified to support "2.". LANG-521

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

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/math/NumberUtils.java?rev=893088&r1=893087&r2=893088&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/math/NumberUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/math/NumberUtils.java Tue
Dec 22 06:52:42 2009
@@ -488,7 +488,7 @@
             }
             dec = null;
         }
-        if (!Character.isDigit(lastChar)) {
+        if (!Character.isDigit(lastChar) && lastChar != '.') {
             if (expPos > -1 && expPos < str.length() - 1) {
                 exp = str.substring(expPos + 1, str.length() - 1);
             } else {
@@ -1385,6 +1385,14 @@
                 // can't have an E at the last byte
                 return false;
             }
+            if (chars[i] == '.') {
+                if (hasDecPoint || hasExp) {
+                    // two decimal points or dec in exponent
+                    return false;
+                }
+                // single trailing decimal point after non-exponent is ok
+                return foundDigit;
+            }
             if (!allowSigns
                 && (chars[i] == 'd'
                     || chars[i] == 'D'

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=893088&r1=893087&r2=893088&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/math/NumberUtilsTest.java
Tue Dec 22 06:52:42 2009
@@ -208,6 +208,9 @@
                 .createNumber("10" + Integer.MAX_VALUE));
         assertEquals("createNumber(String) 18 failed", new BigInteger("10" + Long.MAX_VALUE),
NumberUtils
                 .createNumber("10" + Long.MAX_VALUE));
+
+        // LANG-521
+        assertEquals("createNumber(String) LANG-521 failed", new Float("2."), NumberUtils.createNumber("2."));
     }
 
     public void testCreateFloat() {
@@ -1130,6 +1133,9 @@
         assertTrue("isNumber(String) 24 Neg failed", !NumberUtils.isNumber(val));
         assertTrue("isNumber(String)/createNumber(String) 24 Neg failed", !checkCreateNumber(val));
 
+        // LANG-521
+        val = "2.";
+        assertTrue("isNumber(String) LANG-521 failed", NumberUtils.isNumber(val));
     }
 
     private boolean checkCreateNumber(String val) {



Mime
View raw message