Package org.wildfly.plugin.tools
Class VersionComparator
java.lang.Object
org.wildfly.plugin.tools.VersionComparator
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionint
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.static int
compareVersion
(String v1, String v2) Compares the first version against the second version.static VersionComparator
Returns an instance of a version comparator.static VersionComparator
getInstance
(boolean ignoreSnapshots) Returns an instance of a version comparator which optionally ignore the SNAPSHOT release extension.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
VersionComparator
public VersionComparator()Creates a new version comparator.
-
-
Method Details
-
getInstance
Returns an instance of a version comparator.- Returns:
- a version comparator instance
-
getInstance
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
-true
to ignore the SNAPSHOT release extension, otherwisefalse
which values a SNAPSHOT dependency less than a non-SNAPSHOT of the same version- Returns:
- a version comparator instance
-
compareVersion
Compares the first version against the second version.- Parameters:
v1
- first versionv2
- second version- Returns:
0
if the versions are equal,-1
if version first version is less than the second version or1
if the first version is greater than the second version- See Also:
-
compareVersion
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
ignoreSnapshots
istrue
, the version1.0.0.Final
and1.0.0.Final-SNAPSHOT
are said to be equal. If set tofalse
,1.0.0.Final
is greater than1.0.0.Final-SNAPSHOT
.- Parameters:
ignoreSnapshots
-true
to ignore the SNAPSHOT release extension, otherwisefalse
which values a SNAPSHOT dependency less than a non-SNAPSHOT of the same versionv1
- the first versionv2
- the second version- Returns:
0
if the versions are equal,-1
if version first version is less than the second version or1
if the first version is greater than the second version
-
compare
- Specified by:
compare
in interfaceComparator<String>
-