Class ComparableVersion
java.lang.Object
org.apache.maven.artifact.versioning.ComparableVersion
- All Implemented Interfaces:
Comparable<ComparableVersion>
Generic implementation of version comparison.
Features:- 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,
- strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering.
Well-known qualifiers (case insensitive) are:
alpha
ora
beta
orb
milestone
orm
rc
orcr
snapshot
(the empty string)
orga
orfinal
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 prefer1.0.0-RC1
over1.0.0.RC1
, and more generally:1.0.X2 < 1.0-X3 < 1.0.1
for any stringX
; but prefer1.0.0-X1
over1.0.0.X1
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Represents a numeric item in the version item list.private static class
Represents a numeric item in the version item list that can be represented with an int.private static interface
private static class
Represents a version list item.private static class
Represents a numeric item in the version item list that can be represented with a long.private static class
Represents a string in the version item list, usually a qualifier. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private ComparableVersion.ListItem
private static final int
private static final int
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
int
hashCode()
static void
Main to test version parsing and comparison.private static ComparableVersion.Item
final void
parseVersion
(String version) private static String
stripLeadingZeroes
(String buf) toString()
-
Field Details
-
MAX_INTITEM_LENGTH
private static final int MAX_INTITEM_LENGTH- See Also:
-
MAX_LONGITEM_LENGTH
private static final int MAX_LONGITEM_LENGTH- See Also:
-
value
-
canonical
-
items
-
-
Constructor Details
-
ComparableVersion
-
-
Method Details
-
parseVersion
-
parseItem
-
stripLeadingZeroes
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ComparableVersion>
-
toString
-
getCanonical
-
equals
-
hashCode
public int hashCode() -
main
Main to test version parsing and comparison.To check how "1.2.7" compares to "1.2-SNAPSHOT", for example, you can issue
java -jar ${maven.repo.local}/org/apache/maven/maven-artifact/${maven.version}/maven-artifact-${maven.version}.jar "1.2.7" "1.2-SNAPSHOT"
command to command line. Result of given command will be something like this:Display parameters as parsed by Maven (in canonical form) and comparison result: 1. 1.2.7 == 1.2.7 1.2.7 > 1.2-SNAPSHOT 2. 1.2-SNAPSHOT == 1.2-snapshot
- Parameters:
args
- the version strings to parse and compare. You can pass arbitrary number of version strings and always two adjacent will be compared
-