Skip to content

Commit

Permalink
Merge pull request #511 from dromara/master
Browse files Browse the repository at this point in the history
perfect JreEnum
  • Loading branch information
KamToHung authored Nov 22, 2024
2 parents dc1a4bb + 8f585de commit c228531
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 c228531

Please sign in to comment.