You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2016/09/11 17:20:39 UTC
[1/9] [lang] LANG-1252: better naming and java 6 specifics around
handling a leading +
Repository: commons-lang
Updated Branches:
refs/heads/master 05a6beba7 -> dad86bc0a
LANG-1252: better naming and java 6 specifics around handling a leading +
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c503d742
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c503d742
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c503d742
Branch: refs/heads/master
Commit: c503d742f094dc2048b72c3f78f5e2e6070a44e1
Parents: 1a1fc65
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sat Sep 10 21:01:08 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sat Sep 10 21:01:08 2016 -0400
----------------------------------------------------------------------
.../apache/commons/lang3/math/NumberUtils.java | 42 +++++-
.../apache/commons/lang3/math/package-info.java | 2 +-
.../commons/lang3/math/NumberUtilsTest.java | 144 ++++++++++---------
3 files changed, 119 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c503d742/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 3d59057..3205a6e 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1349,6 +1349,34 @@ public class NumberUtils {
* <p>Checks whether the String a valid Java number.</p>
*
* <p>Valid numbers include hexadecimal marked with the <code>0x</code> or
+ * <code>0X</code> qualifier, octal numbers, scientific notation and numbers
+ * marked with a type qualifier (e.g. 123L).</p>
+ *
+ * <p>Non-hexadecimal strings beginning with a leading zero are
+ * treated as octal values. Thus the string <code>09</code> will return
+ * <code>false</code>, since <code>9</code> is not a valid octal value.
+ * However, numbers beginning with {@code 0.} are treated as decimal.</p>
+ *
+ * <p><code>null</code> and empty/blank {@code String} will return
+ * <code>false</code>.</p>
+ *
+ * <p>Note, {@link #createNumber(String)} should return a number for every
+ * input resuling in <code>true</code>.</p>
+ *
+ * @param str the <code>String</code> to check
+ * @return <code>true</code> if the string is a correctly formatted number
+ * @since 3.3 the code supports hex {@code 0Xhhh} and octal {@code 0ddd} validation
+ * @deprecated This feature will be removed in Lang 4.0, use {@link NumberUtils#isCreatable(String)} instead
+ */
+ @Deprecated
+ public static boolean isNumber(final String str) {
+ return isCreatable(str);
+ }
+
+ /**
+ * <p>Checks whether the String a valid Java number.</p>
+ *
+ * <p>Valid numbers include hexadecimal marked with the <code>0x</code> or
* <code>0X</code> qualifier, octal numbers, scientific notation and numbers
* marked with a type qualifier (e.g. 123L).</p>
*
@@ -1360,11 +1388,14 @@ public class NumberUtils {
* <p><code>null</code> and empty/blank {@code String} will return
* <code>false</code>.</p>
*
+ * <p>Note, {@link #createNumber(String)} should return a number for every
+ * input resuling in <code>true</code>.</p>
+ *
* @param str the <code>String</code> to check
* @return <code>true</code> if the string is a correctly formatted number
* @since 3.3 the code supports hex {@code 0Xhhh} and octal {@code 0ddd} validation
*/
- public static boolean isNumber(final String str) {
+ public static boolean isCreatable(final String str) {
if (StringUtils.isEmpty(str)) {
return false;
}
@@ -1374,8 +1405,10 @@ public class NumberUtils {
boolean hasDecPoint = false;
boolean allowSigns = false;
boolean foundDigit = false;
+ boolean isJava6 = StringUtils.startsWith(System.getProperty("java.version"), "1.6");
// deal with any possible sign up front
- final int start = (chars[0] == '-') ? 1 : 0;
+ final int start = (chars[0] == '-' || chars[0] == '+') ? 1 : 0;
+ final boolean hasLeadingPlusSign = (start == 1 && chars[0] == '+');
if (sz > start + 1 && chars[start] == '0') { // leading 0
if (
(chars[start + 1] == 'x') ||
@@ -1445,6 +1478,9 @@ public class NumberUtils {
}
if (i < chars.length) {
if (chars[i] >= '0' && chars[i] <= '9') {
+ if (isJava6 && hasLeadingPlusSign && !hasDecPoint) {
+ return false;
+ }
// no type qualifier, OK
return true;
}
@@ -1489,7 +1525,7 @@ public class NumberUtils {
* when calling one of those methods.</p>
*
* <p>Hexadecimal and scientific notations are <strong>not</strong> considered parsable.
- * See {@link #isNumber(String)} on those cases.</p>
+ * See {@link #isCreatable(String)} on those cases.</p>
*
* <p>{@code Null} and empty String will return <code>false</code>.</p>
*
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c503d742/src/main/java/org/apache/commons/lang3/math/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/package-info.java b/src/main/java/org/apache/commons/lang3/math/package-info.java
index fd6f862..2ae6306 100644
--- a/src/main/java/org/apache/commons/lang3/math/package-info.java
+++ b/src/main/java/org/apache/commons/lang3/math/package-info.java
@@ -26,7 +26,7 @@
* <p>There are two aspects of this package that should be highlighted.
* The first is {@link org.apache.commons.lang3.math.NumberUtils#createNumber(String)}, a method which does its best to convert a String into a {@link java.lang.Number} object.
* You have no idea what type of Number it will return, so you should call the relevant <code>xxxValue</code> method when you reach the point of needing a number.
- * NumberUtils also has a related {@link org.apache.commons.lang3.math.NumberUtils#isNumber(String) isNumber(String)} method.</p>
+ * NumberUtils also has a related {@link org.apache.commons.lang3.math.NumberUtils#isCreatable(String) isCreatable(String)} method.</p>
*
* @since 2.0
*/
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c503d742/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 9b785f0..5a5814c 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -27,6 +27,7 @@ import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
+import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
/**
@@ -1216,91 +1217,104 @@ public class NumberUtilsTest {
}
/**
- * Tests isNumber(String) and tests that createNumber(String) returns
- * a valid number iff isNumber(String) returns false.
+ * Tests isCreatable(String) and tests that createNumber(String) returns
+ * a valid number iff isCreatable(String) returns false.
*/
@Test
- public void testIsNumber() {
- compareIsNumberWithCreateNumber("12345", true);
- compareIsNumberWithCreateNumber("1234.5", true);
- compareIsNumberWithCreateNumber(".12345", true);
- compareIsNumberWithCreateNumber("1234E5", true);
- compareIsNumberWithCreateNumber("1234E+5", true);
- compareIsNumberWithCreateNumber("1234E-5", true);
- compareIsNumberWithCreateNumber("123.4E5", true);
- compareIsNumberWithCreateNumber("-1234", true);
- compareIsNumberWithCreateNumber("-1234.5", true);
- compareIsNumberWithCreateNumber("-.12345", true);
- compareIsNumberWithCreateNumber("-1234E5", true);
- compareIsNumberWithCreateNumber("0", true);
- compareIsNumberWithCreateNumber("-0", true);
- compareIsNumberWithCreateNumber("01234", true);
- compareIsNumberWithCreateNumber("-01234", true);
- compareIsNumberWithCreateNumber("-0xABC123", true);
- compareIsNumberWithCreateNumber("-0x0", true);
- compareIsNumberWithCreateNumber("123.4E21D", true);
- compareIsNumberWithCreateNumber("-221.23F", true);
- compareIsNumberWithCreateNumber("22338L", true);
-
- compareIsNumberWithCreateNumber(null, false);
- compareIsNumberWithCreateNumber("", false);
- compareIsNumberWithCreateNumber(" ", false);
- compareIsNumberWithCreateNumber("\r\n\t", false);
- compareIsNumberWithCreateNumber("--2.3", false);
- compareIsNumberWithCreateNumber(".12.3", false);
- compareIsNumberWithCreateNumber("-123E", false);
- compareIsNumberWithCreateNumber("-123E+-212", false);
- compareIsNumberWithCreateNumber("-123E2.12", false);
- compareIsNumberWithCreateNumber("0xGF", false);
- compareIsNumberWithCreateNumber("0xFAE-1", false);
- compareIsNumberWithCreateNumber(".", false);
- compareIsNumberWithCreateNumber("-0ABC123", false);
- compareIsNumberWithCreateNumber("123.4E-D", false);
- compareIsNumberWithCreateNumber("123.4ED", false);
- compareIsNumberWithCreateNumber("1234E5l", false);
- compareIsNumberWithCreateNumber("11a", false);
- compareIsNumberWithCreateNumber("1a", false);
- compareIsNumberWithCreateNumber("a", false);
- compareIsNumberWithCreateNumber("11g", false);
- compareIsNumberWithCreateNumber("11z", false);
- compareIsNumberWithCreateNumber("11def", false);
- compareIsNumberWithCreateNumber("11d11", false);
- compareIsNumberWithCreateNumber("11 11", false);
- compareIsNumberWithCreateNumber(" 1111", false);
- compareIsNumberWithCreateNumber("1111 ", false);
-
- compareIsNumberWithCreateNumber("2.", true); // LANG-521
- compareIsNumberWithCreateNumber("1.1L", false); // LANG-664
+ public void testIsCreatable() {
+ compareIsCreatableWithCreateNumber("12345", true);
+ compareIsCreatableWithCreateNumber("1234.5", true);
+ compareIsCreatableWithCreateNumber(".12345", true);
+ compareIsCreatableWithCreateNumber("1234E5", true);
+ compareIsCreatableWithCreateNumber("1234E+5", true);
+ compareIsCreatableWithCreateNumber("1234E-5", true);
+ compareIsCreatableWithCreateNumber("123.4E5", true);
+ compareIsCreatableWithCreateNumber("-1234", true);
+ compareIsCreatableWithCreateNumber("-1234.5", true);
+ compareIsCreatableWithCreateNumber("-.12345", true);
+ compareIsCreatableWithCreateNumber("-1234E5", true);
+ compareIsCreatableWithCreateNumber("0", true);
+ compareIsCreatableWithCreateNumber("-0", true);
+ compareIsCreatableWithCreateNumber("01234", true);
+ compareIsCreatableWithCreateNumber("-01234", true);
+ compareIsCreatableWithCreateNumber("-0xABC123", true);
+ compareIsCreatableWithCreateNumber("-0x0", true);
+ compareIsCreatableWithCreateNumber("123.4E21D", true);
+ compareIsCreatableWithCreateNumber("-221.23F", true);
+ compareIsCreatableWithCreateNumber("22338L", true);
+
+ compareIsCreatableWithCreateNumber(null, false);
+ compareIsCreatableWithCreateNumber("", false);
+ compareIsCreatableWithCreateNumber(" ", false);
+ compareIsCreatableWithCreateNumber("\r\n\t", false);
+ compareIsCreatableWithCreateNumber("--2.3", false);
+ compareIsCreatableWithCreateNumber(".12.3", false);
+ compareIsCreatableWithCreateNumber("-123E", false);
+ compareIsCreatableWithCreateNumber("-123E+-212", false);
+ compareIsCreatableWithCreateNumber("-123E2.12", false);
+ compareIsCreatableWithCreateNumber("0xGF", false);
+ compareIsCreatableWithCreateNumber("0xFAE-1", false);
+ compareIsCreatableWithCreateNumber(".", false);
+ compareIsCreatableWithCreateNumber("-0ABC123", false);
+ compareIsCreatableWithCreateNumber("123.4E-D", false);
+ compareIsCreatableWithCreateNumber("123.4ED", false);
+ compareIsCreatableWithCreateNumber("1234E5l", false);
+ compareIsCreatableWithCreateNumber("11a", false);
+ compareIsCreatableWithCreateNumber("1a", false);
+ compareIsCreatableWithCreateNumber("a", false);
+ compareIsCreatableWithCreateNumber("11g", false);
+ compareIsCreatableWithCreateNumber("11z", false);
+ compareIsCreatableWithCreateNumber("11def", false);
+ compareIsCreatableWithCreateNumber("11d11", false);
+ compareIsCreatableWithCreateNumber("11 11", false);
+ compareIsCreatableWithCreateNumber(" 1111", false);
+ compareIsCreatableWithCreateNumber("1111 ", false);
+
+ compareIsCreatableWithCreateNumber("2.", true); // LANG-521
+ compareIsCreatableWithCreateNumber("1.1L", false); // LANG-664
}
@Test
public void testLANG971() {
- compareIsNumberWithCreateNumber("0085", false);
- compareIsNumberWithCreateNumber("085", false);
- compareIsNumberWithCreateNumber("08", false);
- compareIsNumberWithCreateNumber("07", true);
- compareIsNumberWithCreateNumber("00", true);
+ compareIsCreatableWithCreateNumber("0085", false);
+ compareIsCreatableWithCreateNumber("085", false);
+ compareIsCreatableWithCreateNumber("08", false);
+ compareIsCreatableWithCreateNumber("07", true);
+ compareIsCreatableWithCreateNumber("00", true);
}
@Test
public void testLANG992() {
- compareIsNumberWithCreateNumber("0.0", true);
- compareIsNumberWithCreateNumber("0.4790", true);
+ compareIsCreatableWithCreateNumber("0.0", true);
+ compareIsCreatableWithCreateNumber("0.4790", true);
}
@Test
public void testLANG972() {
- compareIsNumberWithCreateNumber("0xABCD", true);
- compareIsNumberWithCreateNumber("0XABCD", true);
+ compareIsCreatableWithCreateNumber("0xABCD", true);
+ compareIsCreatableWithCreateNumber("0XABCD", true);
}
- private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
- final boolean isValid = NumberUtils.isNumber(val);
+ @Test
+ public void testLANG1252() {
+ //Check idiosyncries between java 1.6 and 1.7,1.8 redarding leading + signs
+ if (StringUtils.startsWith(System.getProperty("java.version"), "1.6")) {
+ compareIsCreatableWithCreateNumber("+2", false);
+ } else {
+ compareIsCreatableWithCreateNumber("+2", true);
+ }
+
+ //The Following should work regardless of 1.6, 1.7, or 1.8
+ compareIsCreatableWithCreateNumber("+2.0", true);
+ }
+
+ private void compareIsCreatableWithCreateNumber(final String val, final boolean expected) {
+ final boolean isValid = NumberUtils.isCreatable(val);
final boolean canCreate = checkCreateNumber(val);
if (isValid == expected && canCreate == expected) {
return;
}
- fail("Expecting "+ expected + " for isNumber/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate);
+ fail("Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate);
}
@Test
[3/9] [lang] LANG-1252: Cleaning up checkstyle warnings: whitespace,
line length
Posted by ch...@apache.org.
LANG-1252: Cleaning up checkstyle warnings: whitespace, line length
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/a2d41db5
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/a2d41db5
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/a2d41db5
Branch: refs/heads/master
Commit: a2d41db55aa46bd4fedb215c978f03e282cf1ffb
Parents: 0a0a35f
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sat Sep 10 21:41:33 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sat Sep 10 21:41:33 2016 -0400
----------------------------------------------------------------------
.../org/apache/commons/lang3/math/NumberUtils.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a2d41db5/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 3205a6e..d68f45f 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1365,8 +1365,10 @@ public class NumberUtils {
*
* @param str the <code>String</code> to check
* @return <code>true</code> if the string is a correctly formatted number
- * @since 3.3 the code supports hex {@code 0Xhhh} and octal {@code 0ddd} validation
- * @deprecated This feature will be removed in Lang 4.0, use {@link NumberUtils#isCreatable(String)} instead
+ * @since 3.3 the code supports hex {@code 0Xhhh} an
+ * octal {@code 0ddd} validation
+ * @deprecated This feature will be removed in Lang 4.0,
+ * use {@link NumberUtils#isCreatable(String)} instead
*/
@Deprecated
public static boolean isNumber(final String str) {
@@ -1377,9 +1379,9 @@ public class NumberUtils {
* <p>Checks whether the String a valid Java number.</p>
*
* <p>Valid numbers include hexadecimal marked with the <code>0x</code> or
- * <code>0X</code> qualifier, octal numbers, scientific notation and numbers
- * marked with a type qualifier (e.g. 123L).</p>
- *
+ * <code>0X</code> qualifier, octal numbers, scientific notation and
+ * numbers marked with a type qualifier (e.g. 123L).</p>
+ *
* <p>Non-hexadecimal strings beginning with a leading zero are
* treated as octal values. Thus the string <code>09</code> will return
* <code>false</code>, since <code>9</code> is not a valid octal value.
@@ -1405,7 +1407,8 @@ public class NumberUtils {
boolean hasDecPoint = false;
boolean allowSigns = false;
boolean foundDigit = false;
- boolean isJava6 = StringUtils.startsWith(System.getProperty("java.version"), "1.6");
+ boolean isJava6 = StringUtils.startsWith(
+ System.getProperty("java.version"), "1.6");
// deal with any possible sign up front
final int start = (chars[0] == '-' || chars[0] == '+') ? 1 : 0;
final boolean hasLeadingPlusSign = (start == 1 && chars[0] == '+');
[6/9] [lang] LANG-1252: replacing system call for java 1.6 to
SystemUtils.IS_JAVA_1_6
Posted by ch...@apache.org.
LANG-1252: replacing system call for java 1.6 to SystemUtils.IS_JAVA_1_6
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/b3c31a37
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/b3c31a37
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/b3c31a37
Branch: refs/heads/master
Commit: b3c31a379e9ad7cd22cb7f0669b82361ced84992
Parents: a266068
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sun Sep 11 10:54:59 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sun Sep 11 10:54:59 2016 -0400
----------------------------------------------------------------------
src/main/java/org/apache/commons/lang3/math/NumberUtils.java | 5 ++---
.../java/org/apache/commons/lang3/math/NumberUtilsTest.java | 3 ++-
2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b3c31a37/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 995ae59..205baf4 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -21,6 +21,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.Validate;
/**
@@ -1407,8 +1408,6 @@ public class NumberUtils {
boolean hasDecPoint = false;
boolean allowSigns = false;
boolean foundDigit = false;
- boolean isJava6 = StringUtils.startsWith(
- System.getProperty("java.version"), "1.6");
// deal with any possible sign up front
final int start = (chars[0] == '-' || chars[0] == '+') ? 1 : 0;
final boolean hasLeadingPlusSign = (start == 1 && chars[0] == '+');
@@ -1481,7 +1480,7 @@ public class NumberUtils {
}
if (i < chars.length) {
if (chars[i] >= '0' && chars[i] <= '9') {
- if (isJava6 && hasLeadingPlusSign && !hasDecPoint) {
+ if (SystemUtils.IS_JAVA_1_6 && hasLeadingPlusSign && !hasDecPoint) {
return false;
}
// no type qualifier, OK
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/b3c31a37/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 ab8b11d..d9eee43 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -28,6 +28,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.SystemUtils;
import org.junit.Test;
/**
@@ -1298,7 +1299,7 @@ public class NumberUtilsTest {
@Test
public void testLANG1252() {
//Check idiosyncries between java 1.6 and 1.7,1.8 redarding leading + signs
- if (StringUtils.startsWith(System.getProperty("java.version"), "1.6")) {
+ if (SystemUtils.IS_JAVA_1_6) {
compareIsCreatableWithCreateNumber("+2", false);
} else {
compareIsCreatableWithCreateNumber("+2", true);
[8/9] [lang] LANG-1252: adding @since and notes to changes.xml
Posted by ch...@apache.org.
LANG-1252: adding @since and notes to changes.xml
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/e64b51c7
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/e64b51c7
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/e64b51c7
Branch: refs/heads/master
Commit: e64b51c70fa9f5e2795e91e6729ebd895f7f3c01
Parents: 204ed00
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sun Sep 11 13:00:53 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sun Sep 11 13:00:53 2016 -0400
----------------------------------------------------------------------
src/changes/changes.xml | 11 +++++++++++
.../java/org/apache/commons/lang3/math/NumberUtils.java | 2 +-
2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e64b51c7/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 025ba34..969ffc8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,17 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.5" date="tba" description="tba">
+ <action issue="LANG-1252" type="fix" dev="chtompki" due-to="Rob Tompkins">Rename NumberUtils.isNumber, isCreatable to better reflect createNumber. Also, accommodated for "+" symbol as prefix in isCreatable and isNumber.</action>
+ <action issue="LANG-1262" type="update" dev="pschumacher" due-to="Ruslan Cheremin">CompareToBuilder.append(Object, Object, Comparator) method is too big to be inlined</action>
+ <action issue="LANG-1230" type="fix" dev="pschumacher" due-to="Philippe Marschall">Remove unnecessary synchronization from registry lookup in EqualsBuilder and HashCodeBuilder</action>
+ <action issue="LANG-1224" type="add" dev="pschumacher" due-to="Caleb Cushing">Extend RandomStringUtils with methods that generate strings between a min and max length</action>
+ <action issue="LANG-1214" type="fix" dev="pschumacher" due-to="Henry Tung">Handle "void" in ClassUtils.getClass()</action>
+ <action issue="LANG-1250" type="fix" dev="pschumacher" due-to="Glease Wang">SerializationUtils#deserialize has unnecessary code and a comment for that</action>
+ <action issue="LANG-1259" type="update" dev="britter" due-to="Dominik Stadler">JavaDoc for ArrayUtils.isNotEmpty() is slightly misleading</action>
+ <action issue="LANG-1257" type="add" dev="ggregory" due-to="Gary Gregory">Add APIs StringUtils.wrapIfMissing(String, char|String)</action>
+ <action issue="LANG-1190" type="fix" dev="pschumacher" due-to="pschumacher">TypeUtils.isAssignable throws NullPointerException when fromType has type variables and toType generic superclass specifies type variable</action>
+ <action issue="LANG-1226" type="fix" dev="pschumacher" due-to="pschumacher">StringUtils#normalizeSpace does not trim the string anymore</action>
+ <action issue="LANG-1251" type="fix" dev="pschumacher" due-to="Takuya Ueshin">SerializationUtils.ClassLoaderAwareObjectInputStream should use static initializer to initialize primitiveTypes map</action>
<action issue="LANG-1253" type="add" dev="ggregory" due-to="adilek">[GitHub issue #170] Add RandomUtils#nextBoolean() method</action>
<action issue="LANG-1247" type="update" dev="chas" due-to="Benoit Wiart">FastDatePrinter generates extra Date objects</action>
<action issue="LANG-1018" type="fix" dev="pschumacher" due-to="Nick Manley">Fix precision loss on NumberUtils.createNumber(String)</action>
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e64b51c7/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 205baf4..7d582de 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1396,7 +1396,7 @@ public class NumberUtils {
*
* @param str the <code>String</code> to check
* @return <code>true</code> if the string is a correctly formatted number
- * @since 3.3 the code supports hex {@code 0Xhhh} and octal {@code 0ddd} validation
+ * @since 3.5 the code supports the "+" suffix on numbers except for integers in Java 1.6
*/
public static boolean isCreatable(final String str) {
if (StringUtils.isEmpty(str)) {
[4/9] [lang] LANG-1252: Few more checkstyle warnings: whitespace,
line length
Posted by ch...@apache.org.
LANG-1252: Few more checkstyle warnings: whitespace, line length
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/71d9e00d
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/71d9e00d
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/71d9e00d
Branch: refs/heads/master
Commit: 71d9e00d42b278ce9d216b33bf1a9c8606fbcb49
Parents: a2d41db
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sat Sep 10 21:43:19 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sat Sep 10 21:43:19 2016 -0400
----------------------------------------------------------------------
src/main/java/org/apache/commons/lang3/math/NumberUtils.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/71d9e00d/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 d68f45f..995ae59 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1349,8 +1349,8 @@ public class NumberUtils {
* <p>Checks whether the String a valid Java number.</p>
*
* <p>Valid numbers include hexadecimal marked with the <code>0x</code> or
- * <code>0X</code> qualifier, octal numbers, scientific notation and numbers
- * marked with a type qualifier (e.g. 123L).</p>
+ * <code>0X</code> qualifier, octal numbers, scientific notation and
+ * numbers marked with a type qualifier (e.g. 123L).</p>
*
* <p>Non-hexadecimal strings beginning with a leading zero are
* treated as octal values. Thus the string <code>09</code> will return
[2/9] [lang] LANG-1252: updates to package-info,
adding name to pom.xml
Posted by ch...@apache.org.
LANG-1252: updates to package-info, adding name to pom.xml
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/0a0a35f5
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/0a0a35f5
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/0a0a35f5
Branch: refs/heads/master
Commit: 0a0a35f54f5e7ab2d10022d3ee244cbc876bdde2
Parents: c503d74
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sat Sep 10 21:07:42 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sat Sep 10 21:07:42 2016 -0400
----------------------------------------------------------------------
pom.xml | 9 +++++++++
.../java/org/apache/commons/lang3/math/package-info.java | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/0a0a35f5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4d31107..ee29439 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,6 +191,15 @@
<role>Java Developer</role>
</roles>
</developer>
+ <developer>
+ <name>Rob Tompkins</name>
+ <id>chtompki</id>
+ <email>chtompki@apache.org</email>
+ <timezone>-5</timezone>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </developer>
</developers>
<contributors>
<contributor>
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/0a0a35f5/src/main/java/org/apache/commons/lang3/math/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/package-info.java b/src/main/java/org/apache/commons/lang3/math/package-info.java
index 2ae6306..16ca5b2 100644
--- a/src/main/java/org/apache/commons/lang3/math/package-info.java
+++ b/src/main/java/org/apache/commons/lang3/math/package-info.java
@@ -26,7 +26,7 @@
* <p>There are two aspects of this package that should be highlighted.
* The first is {@link org.apache.commons.lang3.math.NumberUtils#createNumber(String)}, a method which does its best to convert a String into a {@link java.lang.Number} object.
* You have no idea what type of Number it will return, so you should call the relevant <code>xxxValue</code> method when you reach the point of needing a number.
- * NumberUtils also has a related {@link org.apache.commons.lang3.math.NumberUtils#isCreatable(String) isCreatable(String)} method.</p>
+ * NumberUtils also has a related {@link org.apache.commons.lang3.math.NumberUtils#isCreatable(String)} method.</p>
*
* @since 2.0
*/
[9/9] [lang] Merge branch 'master' of github.com:apache/commons-lang
into LANG-1252
Posted by ch...@apache.org.
Merge branch 'master' of github.com:apache/commons-lang into LANG-1252
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/dad86bc0
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/dad86bc0
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/dad86bc0
Branch: refs/heads/master
Commit: dad86bc0a29689fd29bf03b382a39621718e8b05
Parents: e64b51c 05a6beb
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sun Sep 11 13:01:59 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sun Sep 11 13:01:59 2016 -0400
----------------------------------------------------------------------
src/changes/changes.xml | 4 +-
.../org/apache/commons/lang3/ArrayUtils.java | 665 +++++++++++--------
.../org/apache/commons/lang3/ClassUtils.java | 22 +-
.../commons/lang3/DigitalBase10SizeUnit.java | 393 -----------
.../commons/lang3/DigitalBase2SizeUnit.java | 434 ------------
.../org/apache/commons/lang3/ObjectUtils.java | 20 +-
.../apache/commons/lang3/RandomStringUtils.java | 99 ++-
.../org/apache/commons/lang3/RandomUtils.java | 3 +-
.../commons/lang3/SerializationUtils.java | 27 +-
.../org/apache/commons/lang3/StringUtils.java | 91 ++-
.../org/apache/commons/lang3/XMLCharacter.java | 84 ---
.../commons/lang3/builder/CompareToBuilder.java | 53 +-
.../commons/lang3/builder/EqualsBuilder.java | 22 +-
.../commons/lang3/builder/EqualsExclude.java | 2 +
.../commons/lang3/builder/HashCodeBuilder.java | 22 +-
.../commons/lang3/builder/HashCodeExclude.java | 2 +
.../builder/ReflectionToStringBuilder.java | 2 +-
.../commons/lang3/builder/ToStringExclude.java | 2 +
.../lang3/event/EventListenerSupport.java | 4 +-
.../commons/lang3/exception/ExceptionUtils.java | 21 +-
.../commons/lang3/mutable/MutableByte.java | 4 +
.../commons/lang3/mutable/MutableDouble.java | 4 +
.../commons/lang3/mutable/MutableFloat.java | 4 +
.../commons/lang3/mutable/MutableInt.java | 4 +
.../commons/lang3/mutable/MutableLong.java | 4 +
.../commons/lang3/mutable/MutableShort.java | 4 +
.../commons/lang3/reflect/MethodUtils.java | 103 +--
.../apache/commons/lang3/reflect/TypeUtils.java | 4 +
.../commons/lang3/text/StrSubstitutor.java | 2 +
.../apache/commons/lang3/text/WordUtils.java | 1 +
.../commons/lang3/time/DateFormatUtils.java | 83 ++-
.../apache/commons/lang3/time/DatePrinter.java | 11 +-
.../commons/lang3/time/FastDateFormat.java | 8 +-
.../apache/commons/lang3/ClassUtilsTest.java | 2 +-
.../lang3/DigitalBase10SizeUnitTest.java | 123 ----
.../commons/lang3/DigitalBase2SizeUnitTest.java | 123 ----
.../commons/lang3/RandomStringUtilsTest.java | 155 +++++
.../commons/lang3/StringUtilsContainsTest.java | 477 +++++++++++++
.../lang3/StringUtilsEmptyBlankTest.java | 114 ++++
.../lang3/StringUtilsEqualsIndexOfTest.java | 434 +-----------
.../apache/commons/lang3/StringUtilsIsTest.java | 4 +-
.../apache/commons/lang3/StringUtilsTest.java | 136 ++--
.../commons/lang3/StringUtilsTrimEmptyTest.java | 279 --------
.../commons/lang3/StringUtilsTrimStripTest.java | 239 +++++++
.../apache/commons/lang3/XMLCharacterTest.java | 104 ---
.../commons/lang3/reflect/TypeUtilsTest.java | 17 +
46 files changed, 1873 insertions(+), 2542 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/dad86bc0/src/changes/changes.xml
----------------------------------------------------------------------
[5/9] [lang] LANG-1252: adding test for deprecated isNumber
Posted by ch...@apache.org.
LANG-1252: adding test for deprecated isNumber
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/a2660687
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/a2660687
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/a2660687
Branch: refs/heads/master
Commit: a2660687980b36003a612eb89b40d6fdecb4b153
Parents: 71d9e00
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sun Sep 11 10:51:29 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sun Sep 11 10:51:29 2016 -0400
----------------------------------------------------------------------
.../commons/lang3/math/NumberUtilsTest.java | 67 ++++++++++++++++++++
1 file changed, 67 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/a2660687/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 5a5814c..ab8b11d 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -1316,6 +1316,73 @@ public class NumberUtilsTest {
}
fail("Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate);
}
+
+ /**
+ * Tests isCreatable(String) and tests that createNumber(String) returns
+ * a valid number iff isCreatable(String) returns false.
+ */
+ @Test
+ public void testIsNumber() {
+ compareIsNumberWithCreateNumber("12345", true);
+ compareIsNumberWithCreateNumber("1234.5", true);
+ compareIsNumberWithCreateNumber(".12345", true);
+ compareIsNumberWithCreateNumber("1234E5", true);
+ compareIsNumberWithCreateNumber("1234E+5", true);
+ compareIsNumberWithCreateNumber("1234E-5", true);
+ compareIsNumberWithCreateNumber("123.4E5", true);
+ compareIsNumberWithCreateNumber("-1234", true);
+ compareIsNumberWithCreateNumber("-1234.5", true);
+ compareIsNumberWithCreateNumber("-.12345", true);
+ compareIsNumberWithCreateNumber("-1234E5", true);
+ compareIsNumberWithCreateNumber("0", true);
+ compareIsNumberWithCreateNumber("-0", true);
+ compareIsNumberWithCreateNumber("01234", true);
+ compareIsNumberWithCreateNumber("-01234", true);
+ compareIsNumberWithCreateNumber("-0xABC123", true);
+ compareIsNumberWithCreateNumber("-0x0", true);
+ compareIsNumberWithCreateNumber("123.4E21D", true);
+ compareIsNumberWithCreateNumber("-221.23F", true);
+ compareIsNumberWithCreateNumber("22338L", true);
+
+ compareIsNumberWithCreateNumber(null, false);
+ compareIsNumberWithCreateNumber("", false);
+ compareIsNumberWithCreateNumber(" ", false);
+ compareIsNumberWithCreateNumber("\r\n\t", false);
+ compareIsNumberWithCreateNumber("--2.3", false);
+ compareIsNumberWithCreateNumber(".12.3", false);
+ compareIsNumberWithCreateNumber("-123E", false);
+ compareIsNumberWithCreateNumber("-123E+-212", false);
+ compareIsNumberWithCreateNumber("-123E2.12", false);
+ compareIsNumberWithCreateNumber("0xGF", false);
+ compareIsNumberWithCreateNumber("0xFAE-1", false);
+ compareIsNumberWithCreateNumber(".", false);
+ compareIsNumberWithCreateNumber("-0ABC123", false);
+ compareIsNumberWithCreateNumber("123.4E-D", false);
+ compareIsNumberWithCreateNumber("123.4ED", false);
+ compareIsNumberWithCreateNumber("1234E5l", false);
+ compareIsNumberWithCreateNumber("11a", false);
+ compareIsNumberWithCreateNumber("1a", false);
+ compareIsNumberWithCreateNumber("a", false);
+ compareIsNumberWithCreateNumber("11g", false);
+ compareIsNumberWithCreateNumber("11z", false);
+ compareIsNumberWithCreateNumber("11def", false);
+ compareIsNumberWithCreateNumber("11d11", false);
+ compareIsNumberWithCreateNumber("11 11", false);
+ compareIsNumberWithCreateNumber(" 1111", false);
+ compareIsNumberWithCreateNumber("1111 ", false);
+
+ compareIsNumberWithCreateNumber("2.", true); // LANG-521
+ compareIsNumberWithCreateNumber("1.1L", false); // LANG-664
+ }
+
+ private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
+ final boolean isValid = NumberUtils.isNumber(val);
+ final boolean canCreate = checkCreateNumber(val);
+ if (isValid == expected && canCreate == expected) {
+ return;
+ }
+ fail("Expecting "+ expected + " for isCreatable/createNumber using \"" + val + "\" but got " + isValid + " and " + canCreate);
+ }
@Test
public void testIsParsable() {
[7/9] [lang] LANG-1252: adding more isNumber Tests before full
deletion of method
Posted by ch...@apache.org.
LANG-1252: adding more isNumber Tests before full deletion of method
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/204ed004
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/204ed004
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/204ed004
Branch: refs/heads/master
Commit: 204ed0048f4812201ef65c9a0c44fa54a7d1e04f
Parents: b3c31a3
Author: Rob Tompkins <ch...@gmail.com>
Authored: Sun Sep 11 11:02:01 2016 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Sun Sep 11 11:02:01 2016 -0400
----------------------------------------------------------------------
.../commons/lang3/math/NumberUtilsTest.java | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/204ed004/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 d9eee43..f9c012f 100644
--- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java
@@ -1376,6 +1376,40 @@ public class NumberUtilsTest {
compareIsNumberWithCreateNumber("1.1L", false); // LANG-664
}
+ @Test
+ public void testIsNumberLANG971() {
+ compareIsNumberWithCreateNumber("0085", false);
+ compareIsNumberWithCreateNumber("085", false);
+ compareIsNumberWithCreateNumber("08", false);
+ compareIsNumberWithCreateNumber("07", true);
+ compareIsNumberWithCreateNumber("00", true);
+ }
+
+ @Test
+ public void testIsNumberLANG992() {
+ compareIsNumberWithCreateNumber("0.0", true);
+ compareIsNumberWithCreateNumber("0.4790", true);
+ }
+
+ @Test
+ public void testIsNumberLANG972() {
+ compareIsNumberWithCreateNumber("0xABCD", true);
+ compareIsNumberWithCreateNumber("0XABCD", true);
+ }
+
+ @Test
+ public void testIsNumberLANG1252() {
+ //Check idiosyncries between java 1.6 and 1.7,1.8 redarding leading + signs
+ if (SystemUtils.IS_JAVA_1_6) {
+ compareIsNumberWithCreateNumber("+2", false);
+ } else {
+ compareIsNumberWithCreateNumber("+2", true);
+ }
+
+ //The Following should work regardless of 1.6, 1.7, or 1.8
+ compareIsNumberWithCreateNumber("+2.0", true);
+ }
+
private void compareIsNumberWithCreateNumber(final String val, final boolean expected) {
final boolean isValid = NumberUtils.isNumber(val);
final boolean canCreate = checkCreateNumber(val);