public class ComparableVersion extends java.lang.Object implements java.lang.Comparable<ComparableVersion>
Generic implementation of version comparison.
Features:-
' (hyphen) and '.
' (dot) separators,1.0alpha1 => [1, 0, alpha, 1]
alpha
or a
beta
or b
milestone
or m
rc
or cr
snapshot
(the empty string)
or ga
or final
sp
Modifier and Type | Class and Description |
---|---|
private static class |
ComparableVersion.IntegerItem
Represents a numeric item in the version item list.
|
private static interface |
ComparableVersion.Item |
private static class |
ComparableVersion.ListItem
Represents a version list item.
|
private static class |
ComparableVersion.StringItem
Represents a string in the version item list, usually a qualifier.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
canonical |
private ComparableVersion.ListItem |
items |
private java.lang.String |
value |
Constructor and Description |
---|
ComparableVersion(java.lang.String version) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ComparableVersion o) |
boolean |
equals(java.lang.Object o) |
java.lang.String |
getCanonical() |
int |
hashCode() |
static void |
main(java.lang.String... args)
Main to test version parsing and comparison.
|
private static ComparableVersion.Item |
parseItem(boolean isDigit,
java.lang.String buf) |
void |
parseVersion(java.lang.String version) |
java.lang.String |
toString() |
private java.lang.String value
private java.lang.String canonical
private ComparableVersion.ListItem items
public final void parseVersion(java.lang.String version)
private static ComparableVersion.Item parseItem(boolean isDigit, java.lang.String buf)
public int compareTo(ComparableVersion o)
compareTo
in interface java.lang.Comparable<ComparableVersion>
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getCanonical()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static void main(java.lang.String... args)
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
args
- the version strings to parse and compare. You can pass arbitrary number of version strings and always
two adjacent will be compared