Add SystemUtils.IS_JAVA_21

This commit is contained in:
Emmanuel Bourg 2023-07-05 09:39:25 +02:00
parent f68a643ef9
commit 71340db86f
3 changed files with 51 additions and 0 deletions

View File

@ -190,6 +190,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_18.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_19.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_20.</action>
<action type="add" dev="ebourg" due-to="Emmanuel Bourg">Add SystemUtils.IS_JAVA_21.</action>
<action issue="LANG-1627" type="add" dev="ggregory" due-to="Alberto Scotto, Avijit Chakraborty, Steve Bosman, Bruno P. Kinoshita, Gary Gregory">Add ArrayUtils.oneHot().</action>
<action issue="LANG-1662" type="add" dev="ggregory" due-to="Daniel Augusto Veronezi Salvador, Gary Gregory, Bruno P. Kinoshita">Let ReflectionToStringBuilder only reflect given field names #849.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Enumeration&lt;E&gt;).</action>

View File

@ -1097,6 +1097,19 @@ public class SystemUtils {
*/
public static final boolean IS_JAVA_20 = getJavaVersionMatches("20");
/**
* Is {@code true} if this is Java version 21 (also 21.x versions).
* <p>
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
* </p>
* <p>
* This value is initialized when the class is loaded.
* </p>
*
* @since 3.13.0
*/
public static final boolean IS_JAVA_21 = getJavaVersionMatches("21");
// Operating system checks
// -----------------------------------------------------------------------
// These MUST be declared after those above as they depend on the

View File

@ -78,6 +78,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("1.8")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -100,6 +101,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("9")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -122,6 +124,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("10")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -144,6 +147,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("11")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -166,6 +170,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("12")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -188,6 +193,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("13")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -210,6 +216,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("14")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -232,6 +239,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("15")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -254,6 +262,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("16")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -276,6 +285,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("17")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -298,6 +308,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("18")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -320,6 +331,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertTrue(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("19")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -342,6 +354,7 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertTrue(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("20")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
@ -364,6 +377,30 @@ public class SystemUtilsTest extends AbstractLangTest {
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertTrue(SystemUtils.IS_JAVA_20);
assertTrue(SystemUtils.IS_JAVA_21);
} else if (javaVersion.startsWith("21")) {
assertFalse(SystemUtils.IS_JAVA_1_1);
assertFalse(SystemUtils.IS_JAVA_1_2);
assertFalse(SystemUtils.IS_JAVA_1_3);
assertFalse(SystemUtils.IS_JAVA_1_4);
assertFalse(SystemUtils.IS_JAVA_1_5);
assertFalse(SystemUtils.IS_JAVA_1_6);
assertFalse(SystemUtils.IS_JAVA_1_7);
assertFalse(SystemUtils.IS_JAVA_1_8);
assertFalse(SystemUtils.IS_JAVA_1_9);
assertFalse(SystemUtils.IS_JAVA_9);
assertFalse(SystemUtils.IS_JAVA_10);
assertFalse(SystemUtils.IS_JAVA_11);
assertFalse(SystemUtils.IS_JAVA_12);
assertFalse(SystemUtils.IS_JAVA_13);
assertFalse(SystemUtils.IS_JAVA_14);
assertFalse(SystemUtils.IS_JAVA_15);
assertFalse(SystemUtils.IS_JAVA_16);
assertFalse(SystemUtils.IS_JAVA_17);
assertFalse(SystemUtils.IS_JAVA_18);
assertFalse(SystemUtils.IS_JAVA_19);
assertFalse(SystemUtils.IS_JAVA_20);
assertTrue(SystemUtils.IS_JAVA_21);
} else {
System.out.println("Can't test IS_JAVA value: " + javaVersion);
}