Class VersionChecker

java.lang.Object
com.avrix.utils.VersionChecker

public class VersionChecker extends Object
A set of tools for checking the compatibility of two versions.
  • Constructor Details

    • VersionChecker

      public VersionChecker()
  • Method Details

    • isVersionCompatible

      public static boolean isVersionCompatible(String currentVersion, String versionCondition)
      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

      public static String normalizeVersion(String version)
      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

      public static int compareVersions(String versionOne, String versionTwo)
      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 than 0 if versionOne is less than versionTwo, and a value greater than 0 if versionOne is greater than versionTwo.