Skip to content

Commit

Permalink
Merge pull request #510 from KamToHung/perfect_JreEnum
Browse files Browse the repository at this point in the history
[ISSUE #509] JreEnum lessThan and greaterThan method
  • Loading branch information
KamToHung authored Nov 22, 2024
2 parents bf68d51 + 4b482fd commit 8f585de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions common/src/main/java/org/dromara/dynamictp/common/em/JreEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* JRE version
*
* @author kamtohung
*/
@Slf4j
Expand Down Expand Up @@ -97,4 +98,24 @@ private static JreEnum getJre() {
return JAVA_8;
}

/**
* 判断当前版本是否大于某个版本
*
* @param targetVersion 目标版本
* @return 是否大于
*/
public static boolean greaterThan(JreEnum targetVersion) {
return getJre().ordinal() > targetVersion.ordinal();
}

/**
* 判断当前版本是否小于某个版本
*
* @param targetVersion 目标版本
* @return 是否小于
*/
public static boolean lessThan(JreEnum targetVersion) {
return getJre().ordinal() < targetVersion.ordinal();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ void testJRE11() {
Assertions.assertEquals(JreEnum.JAVA_11, JreEnum.currentVersion());
}

@Test
@EnabledOnJre(value = JRE.JAVA_11)
void testJRE11GreaterThan() {
Assertions.assertTrue(JreEnum.greaterThan(JreEnum.JAVA_8));
}

@Test
@EnabledOnJre(value = JRE.JAVA_8)
void testJRE8LessThan() {
Assertions.assertTrue(JreEnum.lessThan(JreEnum.JAVA_11));
}

}

0 comments on commit 8f585de

Please sign in to comment.