Package io.microsphere.util
Class VersionUtils
- java.lang.Object
-
- io.microsphere.util.VersionUtils
-
-
Field Summary
Fields Modifier and Type Field Description static Version
CURRENT_JAVA_VERSION
TheVersion
instance for current Java Versionstatic Version
JAVA_VERSION_10
TheVersion
instance for Java 10static Version
JAVA_VERSION_11
TheVersion
instance for Java 11static Version
JAVA_VERSION_12
TheVersion
instance for Java 12static Version
JAVA_VERSION_13
TheVersion
instance for Java 13static Version
JAVA_VERSION_14
TheVersion
instance for Java 14static Version
JAVA_VERSION_15
TheVersion
instance for Java 15static Version
JAVA_VERSION_16
TheVersion
instance for Java 16static Version
JAVA_VERSION_17
TheVersion
instance for Java 17static Version
JAVA_VERSION_18
TheVersion
instance for Java 18static Version
JAVA_VERSION_19
TheVersion
instance for Java 19static Version
JAVA_VERSION_20
TheVersion
instance for Java 20static Version
JAVA_VERSION_21
TheVersion
instance for Java 21static Version
JAVA_VERSION_22
TheVersion
instance for Java 22static Version
JAVA_VERSION_23
TheVersion
instance for Java 23static Version
JAVA_VERSION_24
TheVersion
instance for Java 24static Version
JAVA_VERSION_8
TheVersion
instance for Java 8static Version
JAVA_VERSION_9
TheVersion
instance for Java 9static javax.lang.model.SourceVersion
LATEST_JAVA_VERSION
The latestJava Release Version
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
testCurrentJavaVersion(Version.Operator versionOperator, Version comparedVersion)
Determine whethercurrent Java version
matches the specified versionstatic boolean
testCurrentJavaVersion(java.lang.String operatorSymbol, Version comparedVersion)
Determines whether the current Java version matches the specified version based on the given operator symbol.static boolean
testVersion(Version baseVersion, Version.Operator versionOperator, Version comparedVersion)
Determines whether the specified base version matches the compared version based on the given operator.static boolean
testVersion(java.lang.String baseVersion, java.lang.String operatorSymbol, java.lang.String comparedVersion)
Determines whether the specified base version matches the compared version based on the given operator symbol.
-
-
-
Method Detail
-
testCurrentJavaVersion
public static boolean testCurrentJavaVersion(java.lang.String operatorSymbol, Version comparedVersion)
Determines whether the current Java version matches the specified version based on the given operator symbol.Supported Operators
=
- Equal to>
- Greater than>=
- Greater than or equal to<
- Less than<=
- Less than or equal to
Example Usage
VersionUtils.testCurrentJavaVersion("=", VersionUtils.JAVA_VERSION_8); // true if current Java version is 8 VersionUtils.testCurrentJavaVersion(">", VersionUtils.JAVA_VERSION_8); // true if current Java version is higher than 8 VersionUtils.testCurrentJavaVersion("<", VersionUtils.JAVA_VERSION_11); // true if current Java version is lower than 11
- Parameters:
operatorSymbol
- the symbol of the comparison operator; must not be nullcomparedVersion
- the version to compare against; must not be null- Returns:
true
if the result of applying the operator to the current Java version and the compared version is true; otherwise,false
- Throws:
java.lang.IllegalArgumentException
- if any argument is null or the operator symbol is not supported
-
testCurrentJavaVersion
public static boolean testCurrentJavaVersion(Version.Operator versionOperator, Version comparedVersion)
Determine whethercurrent Java version
matches the specified version- Parameters:
versionOperator
- theVersion.Operator
comparedVersion
- theVersion
to be compared- Returns:
true
ifVersion.Operator
matches
current Java version
andcomparedVersion
-
testVersion
public static boolean testVersion(java.lang.String baseVersion, java.lang.String operatorSymbol, java.lang.String comparedVersion)
Determines whether the specified base version matches the compared version based on the given operator symbol.Supported Operators
=
- Equal to>
- Greater than>=
- Greater than or equal to<
- Less than<=
- Less than or equal to
Example Usage
VersionUtils.testVersion("1.8", "=", "1.8.0") == true VersionUtils.testVersion("1.8", ">=", "1.7") == true VersionUtils.testVersion("1.8", "<=", "1.7") == false VersionUtils.testVersion("1.8", "<", "1.7") == false VersionUtils.testVersion("1.8", ">", "1.7") == true
- Parameters:
baseVersion
- the version to be tested; must not be nulloperatorSymbol
- the symbol of the comparison operator; must not be nullcomparedVersion
- the version to compare against; must not be null- Returns:
true
if the result of applying the operator to the base and compared versions is true; otherwise,false
- Throws:
java.lang.IllegalArgumentException
- if any argument is null or the operator symbol is not supported
-
testVersion
public static boolean testVersion(Version baseVersion, Version.Operator versionOperator, Version comparedVersion)
Determines whether the specified base version matches the compared version based on the given operator.Supported Operators
=
- Equal to>
- Greater than>=
- Greater than or equal to<
- Less than<=
- Less than or equal to
Example Usage
Version v1 = Version.of("1.8.0"); Version v2 = Version.of("1.7.0"); Version.Operator eq = Version.Operator.of("="); // Equals Version.Operator gt = Version.Operator.of(">"); // Greater than Version.Operator lt = Version.Operator.of("<"); // Less than testVersion(v1, eq, v1); // true testVersion(v1, gt, v2); // true testVersion(v2, lt, v1); // true
- Parameters:
baseVersion
- the version to be tested; must not be nullversionOperator
- the comparison operator; must not be nullcomparedVersion
- the version to compare against; must not be null- Returns:
true
if the result of applying the operator to the base and compared versions is true; otherwise,false
- Throws:
java.lang.IllegalArgumentException
- if any argument is null
-
-