commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r904658 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/math/NumberUtils.java test/java/org/apache/commons/lang/math/NumberUtilsTest.java
Date Fri, 29 Jan 2010 23:10:27 GMT
Author: niallp
Date: Fri Jan 29 23:10:27 2010
New Revision: 904658

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

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

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java?rev=904658&r1=904657&r2=904658&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/math/NumberUtils.java
Fri Jan 29 23:10:27 2010
@@ -532,7 +532,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 {
@@ -1554,6 +1554,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/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java?rev=904658&r1=904657&r2=904658&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/math/NumberUtilsTest.java
Fri Jan 29 23:10:27 2010
@@ -239,6 +239,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() {
@@ -1160,6 +1163,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