Class Versions


  • public class Versions
    extends Object
    A few simple version comparison utilities.
    • Constructor Detail

      • Versions

        public Versions()
    • Method Detail

      • higherVersion

        public static String higherVersion​(String left,
                                           String right)
        Given two versions, return the higher version
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        the higher of the given versions
      • isStrictlyHigherVersion

        public static boolean isStrictlyHigherVersion​(String left,
                                                      String right)
        Returns true if the "left" version is strictly higher than the "right" version.
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        true if left is greater than right
      • isHigherOrSameVersion

        public static boolean isHigherOrSameVersion​(String left,
                                                    String right)
        Returns true if the "left" version is higher than or equal to the "right" version.
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        true if left is greater than or equal to right
      • isStrictlyLowerVersion

        public static boolean isStrictlyLowerVersion​(String left,
                                                     String right)
        Returns true if the "left" version is strictly lower than the "right" version.
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        true if left is lower than right
      • isLowerOrSameVersion

        public static boolean isLowerOrSameVersion​(String left,
                                                   String right)
        Returns true if the "left" version is lower than or equal to the "right" version.
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        true if left is less than or equal to right
      • isSameVersion

        public static boolean isSameVersion​(String left,
                                            String right)
        Returns true if the "left" version exactly equals the "right" version.
        Parameters:
        left - the first version to compare
        right - the second version to compare
        Returns:
        true if left equals right
      • versionCompare

        public static int versionCompare​(String left,
                                         String right)
        Performs a <=> comparison of numeric version numbers. When a section is determined to be non-numeric, a case-insensitive string comparison is performed.
        Parameters:
        left - the first version number (e.g. "1.2.3")
        right - the second version number (e.g. "1.2.4")
        Returns:
        -1 if "left" is less than "right", 0 if the versions are equal, and 1 if "left" is higher than "right"
        Implementation Note:
        Current implementation works best when versions have the same number of segments, e.g. 2.1.0 vs 2.0.0. It works also with different number of segments when the different segments are numeric, e.g. 1.0.0 vs 1.0.0.42. It does NOT work so well right now when the last different segments are non-numeric, e.g. 1.0.0 vs 1.0.0-SNAPSHOT or 1.0.0-alpha (1.0.0-SNAPSHOT and 1.0.0-alpha are considered higher versions than 1.0.0 currently). See issue #45 which is intended to improve these comparisons.