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
1.0.RC2 < 1.0-RC3 < 1.0.1
; but prefer 1.0.0-RC1
over 1.0.0.RC1
, and more
generally: 1.0.X2 < 1.0-X3 < 1.0.1
for any string X
; but prefer 1.0.0-X1
over 1.0.0.X1
.Modifier and Type | Class and Description |
---|---|
private static class |
ComparableVersion.BigIntegerItem
Represents a numeric item in the version item list.
|
private static class |
ComparableVersion.IntItem
Represents a numeric item in the version item list that can be represented with an int.
|
private static interface |
ComparableVersion.Item |
private static class |
ComparableVersion.ListItem
Represents a version list item.
|
private static class |
ComparableVersion.LongItem
Represents a numeric item in the version item list that can be represented with a long.
|
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 static int |
MAX_INTITEM_LENGTH |
private static int |
MAX_LONGITEM_LENGTH |
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) |
private static java.lang.String |
stripLeadingZeroes(java.lang.String buf) |
java.lang.String |
toString() |
private static final int MAX_INTITEM_LENGTH
private static final int MAX_LONGITEM_LENGTH
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)
private static java.lang.String stripLeadingZeroes(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