On 12 July 2014 10:48, <[email protected]> wrote:
> 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 ) );
Could use the simpler str.substring(1) because str cannot be null here.
> + } 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) {
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]