public class VersionNumber extends Object implements Comparable<Object>
defined explicit
or derived from a string
.
For the latter case, you can query whether a component has been defined explicitly by the given versionString
,
via hasMajor()
, hasMinor()
and hasSub()
.
The state whether a component is defined explicitly is not considered
in the hashCode()
, equals(Object)
or compareTo(Object)
methods,
since the version number itself is treated regardless.
Modifier and Type | Field and Description |
---|---|
protected static short |
HAS_MAJOR |
protected static short |
HAS_MINOR |
protected static short |
HAS_SUB |
protected int |
major |
protected int |
minor |
protected short |
state |
protected int |
strEnd |
protected int |
sub |
static VersionNumber |
zeroVersion
A
zero version instance, w/o any component defined explicitly. |
Modifier | Constructor and Description |
---|---|
|
VersionNumber(int majorRev,
int minorRev,
int subMinorRev)
Explicit version number instantiation, with all components defined explicitly.
|
protected |
VersionNumber(int majorRev,
int minorRev,
int subMinorRev,
int _strEnd,
short _state) |
|
VersionNumber(String versionString)
String derived version number instantiation.
|
|
VersionNumber(String versionString,
Pattern versionPattern)
String derived version number instantiation.
|
|
VersionNumber(String versionString,
String delim)
String derived version number instantiation.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object o) |
int |
compareTo(VersionNumber vo) |
int |
endOfStringMatch()
If constructed with
version-string , returns the string offset after the last matching character,
or 0 if none matched, or -1 if not constructed with a string. |
boolean |
equals(Object o) |
static Pattern |
getDefaultVersionNumberPattern()
Returns the default
pattern using getVersionNumberPattern(String)
with delimiter ".". |
int |
getMajor() |
int |
getMinor() |
int |
getSub() |
static Pattern |
getVersionNumberPattern(String delim)
Returns the
pattern
with Perl regular expression: |
int |
hashCode() |
boolean |
hasMajor()
Returns
true , if the major component is defined explicitly, otherwise false . |
boolean |
hasMinor()
Returns
true , if the optional minor component is defined explicitly, otherwise false . |
boolean |
hasSub()
Returns
true , if the optional sub component is defined explicitly, otherwise false . |
boolean |
isZero()
Returns
true , if all version components are zero, otherwise false . |
String |
toString() |
public static final VersionNumber zeroVersion
zero
version instance, w/o any component defined explicitly.hasMajor()
,
hasMinor()
,
hasSub()
protected final int major
protected final int minor
protected final int sub
protected final int strEnd
protected final short state
protected static final short HAS_MAJOR
protected static final short HAS_MINOR
protected static final short HAS_SUB
protected VersionNumber(int majorRev, int minorRev, int subMinorRev, int _strEnd, short _state)
public VersionNumber(int majorRev, int minorRev, int subMinorRev)
hasMajor()
,
hasMinor()
,
hasSub()
public VersionNumber(String versionString)
Utilizing the default pattern
parser with delimiter ".", see getDefaultVersionNumberPattern()
.
You can query whether a component has been defined explicitly by the given versionString
,
via hasMajor()
, hasMinor()
and hasSub()
.
versionString
- should be given as [MAJOR[.MINOR[.SUB]]]hasMajor()
,
hasMinor()
,
hasSub()
public VersionNumber(String versionString, String delim)
Utilizing pattern
parser created via getVersionNumberPattern(String)
.
You can query whether a component has been defined explicitly by the given versionString
,
via hasMajor()
, hasMinor()
and hasSub()
.
versionString
- should be given as [MAJOR[.MINOR[.SUB]]]delim
- the delimiter, e.g. "."hasMajor()
,
hasMinor()
,
hasSub()
public VersionNumber(String versionString, Pattern versionPattern)
You can query whether a component has been defined explicitly by the given versionString
,
via hasMajor()
, hasMinor()
and hasSub()
.
versionString
- should be given as [MAJOR[.MINOR[.SUB]]]versionPattern
- the pattern
parser, must be compatible w/ getVersionNumberPattern(String)
hasMajor()
,
hasMinor()
,
hasSub()
public static Pattern getVersionNumberPattern(String delim)
pattern
with Perl regular expression:
"\\D*(\\d+)[^\\"+delim+"\\s]*(?:\\"+delim+"\\D*(\\d+)[^\\"+delim+"\\s]*(?:\\"+delim+"\\D*(\\d+))?)?"
A whitespace within the version number will end the parser.
Capture groups represent the major (1), optional minor (2) and optional sub version number (3) component in this order.
Each capture group ignores any leading non-digit and uses only contiguous digits, i.e. ignores pending non-digits.
delim
- the delimiter, e.g. "."public static Pattern getDefaultVersionNumberPattern()
pattern
using getVersionNumberPattern(String)
with delimiter ".".
Instance is cached.
public final boolean isZero()
true
, if all version components are zero, otherwise false
.public final boolean hasMajor()
true
, if the major component is defined explicitly, otherwise false
. Undefined components has the value 0
.public final boolean hasMinor()
true
, if the optional minor component is defined explicitly, otherwise false
. Undefined components has the value 0
.public final boolean hasSub()
true
, if the optional sub component is defined explicitly, otherwise false
. Undefined components has the value 0
.public final int endOfStringMatch()
version-string
, returns the string offset after the last matching character,
or 0
if none matched, or -1
if not constructed with a string.public final int compareTo(Object o)
compareTo
in interface Comparable<Object>
public final int compareTo(VersionNumber vo)
public final int getMajor()
public final int getMinor()
public final int getSub()