public final class VersionNumber extends java.lang.Object implements java.lang.Comparable, StringConversion
8.1.7.0.0
.
VersionNumber
has methods that can compare one instance
of VersionNumber
to another. During comparison,
VersionNumber
attempts to interpret the parts of the
version string as numbers; if two corresponding parts cannot be
compared as numbers, they are split in a leading number, if
present, and a trailing non-number, and then compared numerically
and lexicographically, e.g. 9-eb is before 10-ea and 9-ea
is before 9-eb.
If one VersionNumber
part has more digits and/or
letters than the other, with the first portion of that part
matching, then the VersionNumber
with the longer
part is considered to be later than the other
VersionNumber
, e.g. 9-e is before 9-ea and
9 is before 9.0.
Comparisons occur in a left-to-right manner, part by part. As soon as a difference is detected, then it can be determined which version number is earlier or later.
Examples:
8.1.7
comes after 8.1.6
.
9.0
comes after 8.9.9.9.9.9.9
.
8.0.5
equals 8.0.5
.
8.0.6
comes before
8.0.6.0
.
2.0a
comes before 2.0b
.
9-eb
comes before 10-ea
.
9-ea
comes before 9-eb
.
9-e
comes before 9-eb
.
abc.xyz.qrs
comes before qrs.xyz
.
Comparable
so that collections of
VersionNumber
can be easily sorted.
This class implements StringConversion
so that instances of
VersionNumber
can be persisted and reloaded by
Object2Dom
.
Constructor and Description |
---|
VersionNumber(java.lang.String versionString)
This creates an instance of
VersionNumber based on the
dot-separated version string that is passed in. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(java.lang.Object o) |
int |
countParts()
Determine how many dot-separated parts this VersionNumber has.
|
boolean |
equals(java.lang.Object o)
Compares this instance of
VersionNumber with the
specified VersionNumber and returns true
if the version represented are identical. |
java.lang.String |
getJdkSourceTargetString()
Looking at the version number as a JDK version, derive the value
that is acceptable for the -source and -target Javac options,
e.g.
|
java.lang.String |
getPart(int index)
Get a specific dot-separated part of this VersionNumber.
|
int |
hashCode() |
boolean |
isAfter(java.lang.String version)
Determine if this VersionNumber is after the other version,
e.g.
|
boolean |
isAfter(java.lang.String version,
boolean orEquals)
Determine if this VersionNumber is after or equal to the other version,
e.g.
|
boolean |
isAfter(VersionNumber version)
Determine if this VersionNumber is after the other VersionNumber,
e.g.
|
boolean |
isAfter(VersionNumber version,
boolean orEquals)
Determine if this VersionNumber is after or equal to the other VersionNumber,
e.g.
|
boolean |
isBefore(java.lang.String version)
Determine if this VersionNumber is before the other version,
e.g.
|
boolean |
isBefore(java.lang.String version,
boolean orEquals)
Determine if this VersionNumber is before or equal to the other version,
e.g.
|
boolean |
isBefore(VersionNumber version)
Determine if this VersionNumber is before the other VersionNumber,
e.g.
|
boolean |
isBefore(VersionNumber version,
boolean orEquals)
Determine if this VersionNumber is before or equal to the other VersionNumber,
e.g.
|
java.lang.String |
toString()
Returns the
VersionNumber in dot-separated notation
as a String . |
public VersionNumber(java.lang.String versionString)
VersionNumber
based on the
dot-separated version string that is passed in.versionString
- A version which cannot be nulljava.lang.IllegalArgumentException
- if versionString is nullpublic int countParts()
2
and
if the version string is "3", this method returns 1
.public java.lang.String getPart(int index)
index
- The index of the requested partnull
if index is out of boundspublic final boolean isAfter(VersionNumber version)
version
- the other VersionNumbertrue
if this VersionNumber is after the other
VersionNumber, false
otherwise.public final boolean isAfter(java.lang.String version)
version
- the other versiontrue
if this VersionNumber is after the other
version, false
otherwise.public final boolean isAfter(VersionNumber version, boolean orEquals)
version
- the other VersionNumberorEquals
- if false
, only consider after, otherwise consider after and equals totrue
if this VersionNumber is after or equal to the other
VersionNumber, false
otherwise.public final boolean isAfter(java.lang.String version, boolean orEquals)
version
- the other versionorEquals
- if false
, only consider after, otherwise consider after and equals totrue
if this VersionNumber is after or equal to the other
version, false
otherwise.public final boolean isBefore(VersionNumber version)
version
- the other VersionNumbertrue
if this VersionNumber is before the other
VersionNumber, false
otherwise.public final boolean isBefore(java.lang.String version)
version
- the other versiontrue
if this VersionNumber is before the other
version, false
otherwise.public boolean isBefore(VersionNumber version, boolean orEquals)
version
- the other VersionNumberorEquals
- if false
, only consider before, otherwise consider before and equals totrue
if this VersionNumber is before or equal to the other
VersionNumber, false
otherwise.public boolean isBefore(java.lang.String version, boolean orEquals)
version
- the other versionorEquals
- if false
, only consider before, otherwise consider before and equals totrue
if this VersionNumber is before or equal to the other
version, false
otherwise.public java.lang.String getJdkSourceTargetString()
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public boolean equals(java.lang.Object o)
VersionNumber
with the
specified VersionNumber
and returns true
if the version represented are identical.equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
VersionNumber
in dot-separated notation
as a String
.toString
in class java.lang.Object