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 abeta or bmilestone or mrc or crsnapshot(the empty string) or ga or finalsp| 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.Objectpublic java.lang.String getCanonical()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic 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