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
ConstructorsConstructorDescriptionConvenience 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, waitMethods 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- ifpartComparatoris null
-
VersionComparator
public VersionComparator()Convenience constructor.Equivalent to
VersionComparator(new VersionPartComparator()).
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<String>
-
separateIntoParts
Split a version string into parts.The implementation in
VersionComparatordefines 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
-