Package org.kiwiproject.base
Class Versions
- java.lang.Object
-
- org.kiwiproject.base.Versions
-
public class Versions extends Object
A few simple version comparison utilities.
-
-
Constructor Summary
Constructors Constructor Description Versions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringhigherVersion(String left, String right)Given two versions, return the higher versionstatic booleanisHigherOrSameVersion(String left, String right)Returns true if the "left" version is higher than or equal to the "right" version.static booleanisLowerOrSameVersion(String left, String right)Returns true if the "left" version is lower than or equal to the "right" version.static booleanisSameVersion(String left, String right)Returns true if the "left" version exactly equals the "right" version.static booleanisStrictlyHigherVersion(String left, String right)Returns true if the "left" version is strictly higher than the "right" version.static booleanisStrictlyLowerVersion(String left, String right)Returns true if the "left" version is strictly lower than the "right" version.static intversionCompare(String left, String right)Performs a <=> comparison of numeric version numbers.
-
-
-
Method Detail
-
higherVersion
public static String higherVersion(String left, String right)
Given two versions, return the higher version- Parameters:
left- the first version to compareright- 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 compareright- the second version to compare- Returns:
- true if
leftis greater thanright
-
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 compareright- the second version to compare- Returns:
- true if
leftis greater than or equal toright
-
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 compareright- the second version to compare- Returns:
- true if
leftis lower thanright
-
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 compareright- the second version to compare- Returns:
- true if
leftis less than or equal toright
-
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 compareright- the second version to compare- Returns:
- true if
leftequalsright
-
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.
-
-