From 04df36d4981f7020e934aa455e7b85f93112331a Mon Sep 17 00:00:00 2001 From: kamtohung Date: Fri, 22 Nov 2024 15:01:09 +0800 Subject: [PATCH 1/2] [ISSUE #509] JreEnum lessThan and greaterThan method --- .../dromara/dynamictp/common/em/JreEnum.java | 21 +++++++++++++++++++ .../dynamictp/test/common/em/JreEnumTest.java | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java b/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java index 859da958e..7d30c93eb 100644 --- a/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java +++ b/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java @@ -23,6 +23,7 @@ /** * JRE version + * * @author kamtohung */ @Slf4j @@ -97,4 +98,24 @@ private static JreEnum getJre() { return JAVA_8; } + /** + * 判断当前版本是否大于某个版本 + * + * @param targetVersion 目标版本 + * @return 是否大于 + */ + public boolean greaterThan(JreEnum targetVersion) { + return this.ordinal() > targetVersion.ordinal(); + } + + /** + * 判断当前版本是否小于某个版本 + * + * @param targetVersion 目标版本 + * @return 是否小于 + */ + public boolean lessThan(JreEnum targetVersion) { + return this.ordinal() < targetVersion.ordinal(); + } + } diff --git a/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java b/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java index de5a49c27..404b05933 100644 --- a/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java +++ b/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java @@ -42,4 +42,16 @@ void testJRE11() { Assertions.assertEquals(JreEnum.JAVA_11, JreEnum.currentVersion()); } + @Test + @EnabledOnJre(value = JRE.JAVA_11) + void testJRE11GreaterThan() { + Assertions.assertTrue(JreEnum.JAVA_11.greaterThan(JreEnum.JAVA_8)); + } + + @Test + @EnabledOnJre(value = JRE.JAVA_8) + void testJRE8LessThan() { + Assertions.assertTrue(JreEnum.JAVA_8.lessThan(JreEnum.JAVA_11)); + } + } From 4b482fd5307afa118d9b7306792374fc373203f2 Mon Sep 17 00:00:00 2001 From: kamtohung Date: Fri, 22 Nov 2024 15:04:50 +0800 Subject: [PATCH 2/2] [ISSUE #509] JreEnum lessThan and greaterThan method --- .../java/org/dromara/dynamictp/common/em/JreEnum.java | 8 ++++---- .../org/dromara/dynamictp/test/common/em/JreEnumTest.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java b/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java index 7d30c93eb..ca4e60552 100644 --- a/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java +++ b/common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java @@ -104,8 +104,8 @@ private static JreEnum getJre() { * @param targetVersion 目标版本 * @return 是否大于 */ - public boolean greaterThan(JreEnum targetVersion) { - return this.ordinal() > targetVersion.ordinal(); + public static boolean greaterThan(JreEnum targetVersion) { + return getJre().ordinal() > targetVersion.ordinal(); } /** @@ -114,8 +114,8 @@ public boolean greaterThan(JreEnum targetVersion) { * @param targetVersion 目标版本 * @return 是否小于 */ - public boolean lessThan(JreEnum targetVersion) { - return this.ordinal() < targetVersion.ordinal(); + public static boolean lessThan(JreEnum targetVersion) { + return getJre().ordinal() < targetVersion.ordinal(); } } diff --git a/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java b/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java index 404b05933..0671e9b48 100644 --- a/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java +++ b/test/test-common/src/test/java/org/dromara/dynamictp/test/common/em/JreEnumTest.java @@ -45,13 +45,13 @@ void testJRE11() { @Test @EnabledOnJre(value = JRE.JAVA_11) void testJRE11GreaterThan() { - Assertions.assertTrue(JreEnum.JAVA_11.greaterThan(JreEnum.JAVA_8)); + Assertions.assertTrue(JreEnum.greaterThan(JreEnum.JAVA_8)); } @Test @EnabledOnJre(value = JRE.JAVA_8) void testJRE8LessThan() { - Assertions.assertTrue(JreEnum.JAVA_8.lessThan(JreEnum.JAVA_11)); + Assertions.assertTrue(JreEnum.lessThan(JreEnum.JAVA_11)); } }