From c3b1fefbad0c67c8556ba6b4573f135197f87598 Mon Sep 17 00:00:00 2001 From: pascalschumacher Date: Sun, 11 Feb 2018 11:49:44 +0100 Subject: [PATCH] NumberUtils#isCreatable: remove java 6 only code, as commons-lang requires at java 7+ now --- .../commons/lang3/math/NumberUtils.java | 7 +------ .../commons/lang3/math/NumberUtilsTest.java | 19 ++----------------- 2 files changed, 3 insertions(+), 23 deletions(-) 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 1175f5dfb..5942db7f3 100644 --- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java +++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java @@ -21,7 +21,6 @@ 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; /** @@ -1394,7 +1393,7 @@ public class NumberUtils { * * @param str the String to check * @return true if the string is a correctly formatted number - * @since 3.5 the code supports the "+" suffix on numbers except for integers in Java 1.6 + * @since 3.5 */ public static boolean isCreatable(final String str) { if (StringUtils.isEmpty(str)) { @@ -1408,7 +1407,6 @@ public class NumberUtils { boolean foundDigit = false; // deal with any possible sign up front 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' || chars[start + 1] == 'X') { // leading 0x/0X int i = start + 2; @@ -1475,9 +1473,6 @@ public class NumberUtils { } if (i < chars.length) { if (chars[i] >= '0' && chars[i] <= '9') { - if (SystemUtils.IS_JAVA_1_6 && hasLeadingPlusSign && !hasDecPoint) { - return false; - } // no type qualifier, OK return true; } 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 31ca17435..20d87fe30 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -27,7 +27,6 @@ import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.commons.lang3.SystemUtils; import org.junit.Test; /** @@ -1298,14 +1297,7 @@ public class NumberUtilsTest { @Test public void testLANG1252() { - //Check idiosyncrasies between java 1.6 and 1.7, 1.8 regarding leading + signs - if (SystemUtils.IS_JAVA_1_6) { - compareIsCreatableWithCreateNumber("+2", false); - } else { - compareIsCreatableWithCreateNumber("+2", true); - } - - //The Following should work regardless of 1.6, 1.7, or 1.8 + compareIsCreatableWithCreateNumber("+2", true); compareIsCreatableWithCreateNumber("+2.0", true); } @@ -1399,14 +1391,7 @@ public class NumberUtilsTest { @Test public void testIsNumberLANG1252() { - //Check idiosyncrasies between java 1.6 and 1.7,1.8 regarding 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", true); compareIsNumberWithCreateNumber("+2.0", true); }