Package com.atlassian.plugin.util
Class VersionStringComparator
java.lang.Object
com.atlassian.plugin.util.VersionStringComparator
- All Implemented Interfaces:
Comparator<String>
Compares dotted version strings of varying length. Makes a best effort with
other delimiters and non-numeric versions.
For dotted decimals, comparison is as you'd expect: 0.1 is before 0.2 is before 1.0 is before 2.0. This works for any number of dots.
More complicated version numbers are compared by splitting the version strings
into components using the DELIMITER_PATTERN and comparing each
component in order. The first difference found when comparing components
left-to-right is returned.
Two numeric components (containing only digits) are compared as integers. A
numeric component comes after any non-numeric one. Two non-numeric components
are ordered by String.compareToIgnoreCase(String).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares two version strings using the algorithm described above.static booleanisSnapshotVersion(String version) static booleanisValidVersionString(String version) 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
-
Field Details
-
DELIMITER_PATTERN
- See Also:
-
COMPONENT_PATTERN
- See Also:
-
VALID_VERSION_PATTERN
- See Also:
-
SNAPSHOT_PATTERN
-
-
Constructor Details
-
VersionStringComparator
public VersionStringComparator()
-
-
Method Details
-
isValidVersionString
-
isSnapshotVersion
-
compare
Compares two version strings using the algorithm described above.- Specified by:
comparein interfaceComparator<String>- Returns:
-1if version1 is before version2,1if version2 is before version1, or0if the versions are equal.- Throws:
IllegalArgumentException- if either argument does not matchVALID_VERSION_PATTERN.- See Also:
-