You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/04/01 15:53:29 UTC

[commons-lang] 02/02: Add SystemUtils.IS_JAVA_20

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit fee35ddc141a65a4956290864598e825214c4cff
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Apr 1 11:53:21 2023 -0400

    Add SystemUtils.IS_JAVA_20
---
 src/changes/changes.xml                            |  1 +
 .../java/org/apache/commons/lang3/SystemUtils.java | 13 ++++++++
 .../org/apache/commons/lang3/SystemUtilsTest.java  | 35 ++++++++++++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 421e44b2c..a94d53885 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -178,6 +178,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add SystemUtils.IS_JAVA_17.</action>
     <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 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>
diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java
index 95d936ec0..fb945b59c 100644
--- a/src/main/java/org/apache/commons/lang3/SystemUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java
@@ -1084,6 +1084,19 @@ public class SystemUtils {
      */
     public static final boolean IS_JAVA_19 = getJavaVersionMatches("19");
 
+    /**
+     * Is {@code true} if this is Java version 20 (also 20.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_20 = getJavaVersionMatches("20");
+
     // Operating system checks
     // -----------------------------------------------------------------------
     // These MUST be declared after those above as they depend on the
diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
index f62379c3e..f903682de 100644
--- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
@@ -77,6 +77,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("1.8")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -98,6 +99,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("9")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -119,6 +121,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("10")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -140,6 +143,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("11")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -161,6 +165,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("12")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -182,6 +187,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("13")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -203,6 +209,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("14")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -224,6 +231,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("15")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -245,6 +253,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("16")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -266,6 +275,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("17")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -287,6 +297,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertTrue(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("18")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -308,6 +319,7 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertTrue(SystemUtils.IS_JAVA_18);
             assertFalse(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
         } else if (javaVersion.startsWith("19")) {
             assertFalse(SystemUtils.IS_JAVA_1_1);
             assertFalse(SystemUtils.IS_JAVA_1_2);
@@ -329,6 +341,29 @@ public class SystemUtilsTest extends AbstractLangTest {
             assertFalse(SystemUtils.IS_JAVA_17);
             assertFalse(SystemUtils.IS_JAVA_18);
             assertTrue(SystemUtils.IS_JAVA_19);
+            assertFalse(SystemUtils.IS_JAVA_20);
+        } else if (javaVersion.startsWith("20")) {
+            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);
+            assertTrue(SystemUtils.IS_JAVA_20);
         } else {
             System.out.println("Can't test IS_JAVA value: " + javaVersion);
         }