Class VersionComparator
- java.lang.Object
-
- com.composum.sling.core.pckgmgr.regpckg.util.VersionComparator
-
- All Implemented Interfaces:
Comparator<String>
public class VersionComparator extends Object implements Comparator<String>
Since as of version 3.6.6Version.compareTo(Version)
is incompatible with maven version ordering, this implements maven semantics. (it'll order e.g. 1.2.3-SNAPSHOT after 1.2.3, while 1.2.3 is the release that is created after all snapshots).The functionality is specifically:
- mixing of '
-
' (hyphen) and '.
' (dot) separators, - transition between characters and digits also constitutes a separator:
1.0alpha1 => [1, 0, alpha, 1]
- unlimited number of version components,
- version components in the text can be digits or strings,
-
String qualifiers are ordered lexically (case insensitive), with the following exceptions:
- 'snapshot' < '' < 'sp'
- 'a' -> 'alpha'
- 'b' -> 'beta'
- 'm' -> 'milestone'
- 'cr' -> 'rc'
- 'final' -> ''
- 'final' -> ''
- 'final' -> ''
-
Following semver rules is encouraged, and some qualifiers are discouraged (no matter the case):
- The usage of 'CR' qualifier is discouraged. Use 'RC' instead.
- The usage of 'final', 'ga', and 'release' qualifiers is discouraged. Use no qualifier instead.
- The usage of 'SP' qualifier is discouraged. Increment the patch version instead.
- alpha = a < beta = b < milestone = m < rc = cr < snapshot < '' = final = ga = release < sp
- a hyphen usually precedes a qualifier, and is always less important than digits/number, for example 1.0.RC2 < 1.0-RC3 < 1.0.1 ; but prefer '1.0.0-RC1' over '1.0.0.RC1'
- See Also:
- "https://github.com/apache/maven/blob/maven-3.8.6/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java"
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VersionComparator.PackageIdByGroupAndNameComparator
ComparesPackageId
by group and name only, ignoring the version.static class
VersionComparator.PackageIdComparator
Comparator that usescompare(String, String)
with PackageIds, sincePackageId.compareTo(PackageId)
uses (as of filevault-3.6.6) the wrt.
-
Constructor Summary
Constructors Constructor Description VersionComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(String o1, String o2)
-
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
-
-
-
-
Method Detail
-
compare
public int compare(String o1, String o2)
- Specified by:
compare
in interfaceComparator<String>
-
-