Skip to content

Commit

Permalink
[ISSUE #509] JreEnum lessThan and greaterThan method
Browse files Browse the repository at this point in the history
  • Loading branch information
KamToHung committed Nov 22, 2024
1 parent 40b89de commit 04df36d
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 boolean greaterThan(JreEnum targetVersion) {
return this.ordinal() > targetVersion.ordinal();
}

/**
* 判断当前版本是否小于某个版本
*
* @param targetVersion 目标版本
* @return 是否小于
*/
public boolean lessThan(JreEnum targetVersion) {
return this.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.JAVA_11.greaterThan(JreEnum.JAVA_8));
}

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

}

0 comments on commit 04df36d

Please sign in to comment.