-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Lang project for Java 11 (#541)
- Loading branch information
Showing
30 changed files
with
416 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
index 0a34fea8f..40f8830c9 100644 | ||
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
@@ -69,7 +69,17 @@ public enum JavaVersion { | ||
/** | ||
* Java 1.8. | ||
*/ | ||
- JAVA_1_8(1.8f, "1.8"); | ||
+ JAVA_1_8(1.8f, "1.8"), | ||
+ | ||
+ /** | ||
+ * Java 1.9. | ||
+ */ | ||
+ JAVA_1_9(1.9f, "1.9"), | ||
+ | ||
+ /** | ||
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used. | ||
+ */ | ||
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion())); | ||
|
||
/** | ||
* The float value. | ||
@@ -147,9 +157,21 @@ static JavaVersion get(final String nom) { | ||
return JAVA_1_7; | ||
} else if ("1.8".equals(nom)) { | ||
return JAVA_1_8; | ||
- } else { | ||
+ } else if ("1.9".equals(nom)) { | ||
+ return JAVA_1_9; | ||
+ } | ||
+ if (nom == null) { | ||
return null; | ||
} | ||
+ final float v = toFloatVersion(nom); | ||
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9 | ||
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(',')); | ||
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma)); | ||
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) { | ||
+ return JAVA_RECENT; | ||
+ } | ||
+ } | ||
+ return null; | ||
} | ||
|
||
//----------------------------------------------------------------------- | ||
@@ -165,4 +187,24 @@ public String toString() { | ||
return name; | ||
} | ||
|
||
+ // upper bound of java version considering 2. or current is the higher | ||
+ private static float maxVersion() { | ||
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0")); | ||
+ if (v > 0) { | ||
+ return v; | ||
+ } | ||
+ return 2f; | ||
+ } | ||
+ | ||
+ private static float toFloatVersion(final String name) { | ||
+ final String[] toParse = name.split("\\."); | ||
+ if (toParse.length >= 2) { | ||
+ try { | ||
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]); | ||
+ } catch (final NumberFormatException nfe) { | ||
+ // no-op, let use default | ||
+ } | ||
+ } | ||
+ return -1; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
index e65ba73f4..df52fc50f 100644 | ||
--- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java | ||
+++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java | ||
@@ -521,7 +521,7 @@ public class TypeUtilsTest<B> { | ||
public void testTypesSatisfyVariables() throws SecurityException, NoSuchFieldException, | ||
NoSuchMethodException { | ||
final Map<TypeVariable<?>, Type> typeVarAssigns = new HashMap<TypeVariable<?>, Type>(); | ||
- final Integer max = TypeUtilsTest.stub(); | ||
+ final Integer max = TypeUtilsTest.<Integer> stub(); | ||
typeVarAssigns.put(getClass().getMethod("stub").getTypeParameters()[0], Integer.class); | ||
Assert.assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns)); | ||
typeVarAssigns.clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
index 0a34fea8f..40f8830c9 100644 | ||
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
@@ -69,7 +69,17 @@ public enum JavaVersion { | ||
/** | ||
* Java 1.8. | ||
*/ | ||
- JAVA_1_8(1.8f, "1.8"); | ||
+ JAVA_1_8(1.8f, "1.8"), | ||
+ | ||
+ /** | ||
+ * Java 1.9. | ||
+ */ | ||
+ JAVA_1_9(1.9f, "1.9"), | ||
+ | ||
+ /** | ||
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used. | ||
+ */ | ||
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion())); | ||
|
||
/** | ||
* The float value. | ||
@@ -147,9 +157,21 @@ static JavaVersion get(final String nom) { | ||
return JAVA_1_7; | ||
} else if ("1.8".equals(nom)) { | ||
return JAVA_1_8; | ||
- } else { | ||
+ } else if ("1.9".equals(nom)) { | ||
+ return JAVA_1_9; | ||
+ } | ||
+ if (nom == null) { | ||
return null; | ||
} | ||
+ final float v = toFloatVersion(nom); | ||
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9 | ||
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(',')); | ||
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma)); | ||
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) { | ||
+ return JAVA_RECENT; | ||
+ } | ||
+ } | ||
+ return null; | ||
} | ||
|
||
//----------------------------------------------------------------------- | ||
@@ -165,4 +187,24 @@ public String toString() { | ||
return name; | ||
} | ||
|
||
+ // upper bound of java version considering 2. or current is the higher | ||
+ private static float maxVersion() { | ||
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0")); | ||
+ if (v > 0) { | ||
+ return v; | ||
+ } | ||
+ return 2f; | ||
+ } | ||
+ | ||
+ private static float toFloatVersion(final String name) { | ||
+ final String[] toParse = name.split("\\."); | ||
+ if (toParse.length >= 2) { | ||
+ try { | ||
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]); | ||
+ } catch (final NumberFormatException nfe) { | ||
+ // no-op, let use default | ||
+ } | ||
+ } | ||
+ return -1; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
index 477495a4e..93e5bc142 100644 | ||
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java | ||
@@ -36,7 +36,17 @@ public enum JavaVersion { | ||
JAVA_1_5(1.5f, "1.5"), | ||
JAVA_1_6(1.6f, "1.6"), | ||
JAVA_1_7(1.7f, "1.7"), | ||
- JAVA_1_8(1.8f, "1.8"); | ||
+ JAVA_1_8(1.8f, "1.8"), | ||
+ | ||
+ /** | ||
+ * Java 1.9. | ||
+ */ | ||
+ JAVA_1_9(1.9f, "1.9"), | ||
+ | ||
+ /** | ||
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used. | ||
+ */ | ||
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion())); | ||
|
||
/** | ||
* The float value. | ||
@@ -114,10 +124,22 @@ public enum JavaVersion { | ||
return JAVA_1_7; | ||
} else if ("1.8".equals(nom)) { | ||
return JAVA_1_8; | ||
- } else { | ||
+ } else if ("1.9".equals(nom)) { | ||
+ return JAVA_1_9; | ||
+ } | ||
+ if (nom == null) { | ||
return null; | ||
} | ||
- } | ||
+ final float v = toFloatVersion(nom); | ||
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9 | ||
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(',')); | ||
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma)); | ||
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) { | ||
+ return JAVA_RECENT; | ||
+ } | ||
+ } | ||
+ return null; | ||
+ } | ||
|
||
//----------------------------------------------------------------------- | ||
/** | ||
@@ -132,4 +154,25 @@ public enum JavaVersion { | ||
return name; | ||
} | ||
|
||
+ // upper bound of java version considering 2. or current is the higher | ||
+ private static float maxVersion() { | ||
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0")); | ||
+ if (v > 0) { | ||
+ return v; | ||
+ } | ||
+ return 2f; | ||
+ } | ||
+ | ||
+ private static float toFloatVersion(final String name) { | ||
+ final String[] toParse = name.split("\\."); | ||
+ if (toParse.length >= 2) { | ||
+ try { | ||
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]); | ||
+ } catch (final NumberFormatException nfe) { | ||
+ // no-op, let use default | ||
+ } | ||
+ } | ||
+ return -1; | ||
+ } | ||
+ | ||
} |
Oops, something went wrong.