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)); + } + }