You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2016/05/11 19:48:51 UTC
[1/2] [lang] LANG-1151: Performance improvements for
NumberUtils.isParsable (closes #99)
Repository: commons-lang
Updated Branches:
refs/heads/master ec8bf5281 -> 28f7862ab
LANG-1151: Performance improvements for NumberUtils.isParsable (closes #99)
~2.5x performance increase wrt 3.4 version; added a couple checks more to unit tests
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/54ff33b2
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/54ff33b2
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/54ff33b2
Branch: refs/heads/master
Commit: 54ff33b2ad26e3969cc59d7f2723563dee3e37dc
Parents: ec8bf52
Author: Juan Pablo Santos Rodr�guez <ju...@gmail.com>
Authored: Mon Jun 22 13:53:06 2015 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Wed May 11 21:43:36 2016 +0200
----------------------------------------------------------------------
.../apache/commons/lang3/math/NumberUtils.java | 32 +++++++++++++++++---
.../commons/lang3/math/NumberUtilsTest.java | 2 ++
2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/54ff33b2/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index c640ceb..d602524 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1504,13 +1504,37 @@ public class NumberUtils {
* @since 3.4
*/
public static boolean isParsable(final String str) {
- if( StringUtils.endsWith( str, "." ) ) {
+ if (StringUtils.isEmpty(str)) {
+ return false;
+ }
+ if (str.charAt(str.length() - 1) == '.') {
return false;
}
- if( StringUtils.startsWith( str, "-" ) ) {
- return isDigits( StringUtils.replaceOnce( str.substring(1), ".", StringUtils.EMPTY ) );
+ if (str.charAt(0) == '-') {
+ if (str.length() == 1) {
+ return false;
+ }
+ return withDecimalsParsing(str, 1);
+ } else {
+ return withDecimalsParsing(str, 0);
+ }
+ }
+
+ private static boolean withDecimalsParsing(final String str, final int beginIdx) {
+ int decimalPoints = 0;
+ for (int i = beginIdx; i < str.length(); i++) {
+ final boolean isDecimalPoint = str.charAt(i) == '.';
+ if (str.charAt(i) == '.') {
+ decimalPoints++;
+ }
+ if (decimalPoints > 1) {
+ return false;
+ }
+ if (!isDecimalPoint && !Character.isDigit(str.charAt(i))) {
+ return false;
+ }
}
- return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
+ return true;
}
/**
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/54ff33b2/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
index 92977d5..236084b 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -1304,6 +1304,8 @@ public class NumberUtilsTest {
assertFalse( NumberUtils.isParsable("64.2.2") );
assertFalse( NumberUtils.isParsable("64.") );
assertFalse( NumberUtils.isParsable("64L") );
+ assertFalse( NumberUtils.isParsable("-") );
+ assertFalse( NumberUtils.isParsable("--2") );
assertTrue( NumberUtils.isParsable("64.2") );
assertTrue( NumberUtils.isParsable("64") );
assertTrue( NumberUtils.isParsable("018") );
[2/2] [lang] LANG-1151: add changes.xml entry
Posted by pa...@apache.org.
LANG-1151: add changes.xml entry
(side effect close #140)
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/28f7862a
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/28f7862a
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/28f7862a
Branch: refs/heads/master
Commit: 28f7862ab7c5b782977e839bdcb7853d01a7d8b3
Parents: 54ff33b
Author: pascalschumacher <pa...@gmx.net>
Authored: Wed May 11 21:48:40 2016 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Wed May 11 21:48:40 2016 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/28f7862a/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3877a66..779375c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,7 +22,8 @@
<body>
<release version="3.5" date="tba" description="tba">
- <action issue="LANG-1227" type="new" dev="pschumacher" due-to="kaching88">StringUtils.stripAccents should remove accents from "\u0141" and "\u0142".</action>
+ <action issue="LANG-1151" type="update" dev="pschumacher" due-to="Juan Pablo Santos Rodr�guez">Performance improvements for NumberUtils.isParsable</action>
+ <action issue="LANG-1227" type="fix" dev="pschumacher" due-to="kaching88">StringUtils.stripAccents should remove accents from "\u0141" and "\u0142".</action>
<action issue="LANG-1227" type="new" dev="ggregory" due-to="Gary Gregory">Add XMLCharacter class.</action>
<action issue="LANG-1218" type="update" dev="ggregory" due-to="Ruslan Cheremin">EqualsBuilder.append(Object,Object) is too big to be inlined, which prevents whole builder to be scalarized</action>
<action issue="LANG-1205" type="fix" dev="chas" due-to="pbrose">NumberUtils.createNumber() behaves inconsistently with NumberUtils.isNumber()</action>