Thanks! I've implemented the suggested improvement in revision 1623872. 2014-08-30 19:28 GMT+02:00 sebb <seb...@gmail.com>:
> On 12 July 2014 10:48, <brit...@apache.org> 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: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > -- http://people.apache.org/~britter/ http://www.systemoutprintln.de/ http://twitter.com/BenediktRitter http://github.com/britter