Package com.avrix.utils
Class VersionChecker
java.lang.Object
com.avrix.utils.VersionChecker
A set of tools for checking the compatibility of two versions.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
compareVersions
(String versionOne, String versionTwo) Compares two version strings.static boolean
isVersionCompatible
(String currentVersion, String versionCondition) Checks whether a version meets a given condition.static String
normalizeVersion
(String version) Normalizes the version string, leaving only numbers, dashes, periods and underscores.
-
Constructor Details
-
VersionChecker
public VersionChecker()
-
-
Method Details
-
isVersionCompatible
Checks whether a version meets a given condition.- Parameters:
currentVersion
- The current version for comparison, for example, "41.78.16".versionCondition
- Version condition, for example, ">=41.78.16".- Returns:
- true if the current version matches the condition.
-
normalizeVersion
Normalizes the version string, leaving only numbers, dashes, periods and underscores. Removes the last character if it is not a number.- Parameters:
version
- The version string to normalize.- Returns:
- The normalized version string.
-
compareVersions
Compares two version strings.The comparison is based on the normalized versions, where non-numeric characters except for dots (.), dashes (-), and underscores (_) are removed, and dashes and underscores are replaced by dots. If a version segment is empty, it is considered as zero (0). If the last character of a version is not a digit, it is removed.
- Parameters:
versionOne
- the first version string to compare.versionTwo
- the second version string to compare.- Returns:
0
if both versions are equal, a value less than0
ifversionOne
is less thanversionTwo
, and a value greater than0
ifversionOne
is greater thanversionTwo
.
-