Class VersionComparator
- All Implemented Interfaces:
Comparator<String>
Version numbers are broken up into parts, where a part is a contiguous sequence
of one or more digits, or a contiguous sequence of one or more non-digits, and where the period character
('.') serves as a part separator. Then, parts are compared pair-wise until there is a difference, as
determined by the Comparator
provided to the constructor, or one version string runs out of parts,
in which case it is less than the other.
-
Constructor Summary
ConstructorDescriptionConvenience constructor.VersionComparator
(Comparator<String> partComparator) Primary constructor. -
Method Summary
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
Primary constructor.- Parameters:
partComparator
- compares individual parts- Throws:
IllegalArgumentException
- ifpartComparator
is null
-
VersionComparator
public VersionComparator()Convenience constructor.Equivalent to
VersionComparator(new VersionPartComparator())
.
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<String>
-
separateIntoParts
Split a version string into parts.The implementation in
VersionComparator
defines a part as a contiguous sequence of one or more digits, or a contiguous sequence of one or more non-digits, and where the period character ('.') serves as a part separator.Subclasses may choose to override this method to define parts differently.
- Parameters:
version
- the original version string- Returns:
- the parts of the version string
-