- java.lang.Object
-
- org.wildfly.plugin.tools.VersionComparator
-
- All Implemented Interfaces:
Comparator<String>
public class VersionComparator extends Object implements Comparator<String>
Compares two versions. The comparison is case-insensitive.Some qualifiers map to other qualifiers. Below is a table of those mappings.
Qualifier Mapping GA Final a Alpha b Beta m Milestone cr rc - Author:
- James R. Perkins
-
-
Constructor Summary
Constructors Constructor Description VersionComparator()Creates a new version comparator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(String o1, String o2)static intcompareVersion(boolean ignoreSnapshots, String v1, String v2)Compares the first version against the second version optionally ignoring if either version has a SNAPSHOT release extension.static intcompareVersion(String v1, String v2)Compares the first version against the second version.static VersionComparatorgetInstance()Returns an instance of a version comparator.static VersionComparatorgetInstance(boolean ignoreSnapshots)Returns an instance of a version comparator which optionally ignore the SNAPSHOT release extension.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Method Detail
-
getInstance
public static VersionComparator getInstance()
Returns an instance of a version comparator.- Returns:
- a version comparator instance
-
getInstance
public static VersionComparator getInstance(boolean ignoreSnapshots)
Returns an instance of a version comparator which optionally ignore the SNAPSHOT release extension. This can be useful for cases where you want to compare a version is at least a base version, not caring if it's a SNAPSHOT.- Parameters:
ignoreSnapshots-trueto ignore the SNAPSHOT release extension, otherwisefalsewhich values a SNAPSHOT dependency less than a non-SNAPSHOT of the same version- Returns:
- a version comparator instance
-
compareVersion
public static int compareVersion(String v1, String v2)
Compares the first version against the second version.- Parameters:
v1- first versionv2- second version- Returns:
0if the versions are equal,-1if version first version is less than the second version or1if the first version is greater than the second version- See Also:
Comparator.compare(Object, Object)
-
compareVersion
public static int compareVersion(boolean ignoreSnapshots, String v1, String v2)Compares the first version against the second version optionally ignoring if either version has a SNAPSHOT release extension. This can be useful for cases where you want to compare a version is at least a base version, not caring if it's a SNAPSHOT.If
ignoreSnapshotsistrue, the version1.0.0.Finaland1.0.0.Final-SNAPSHOTare said to be equal. If set tofalse,1.0.0.Finalis greater than1.0.0.Final-SNAPSHOT.- Parameters:
ignoreSnapshots-trueto ignore the SNAPSHOT release extension, otherwisefalsewhich values a SNAPSHOT dependency less than a non-SNAPSHOT of the same versionv1- the first versionv2- the second version- Returns:
0if the versions are equal,-1if version first version is less than the second version or1if the first version is greater than the second version
-
compare
public int compare(String o1, String o2)
- Specified by:
comparein interfaceComparator<String>
-
-