Package com.xmlmind.util
Class VersionNumber
- java.lang.Object
-
- com.xmlmind.util.VersionNumber
-
- All Implemented Interfaces:
Comparable<VersionNumber>
public final class VersionNumber extends Object implements Comparable<VersionNumber>
Structured version numbers similar to those used for the JavaTM runtime (example: 1.5.0_06).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VersionNumber.LevelType
Type of the release: alpha, beta, release candidate or patch.
-
Field Summary
Fields Modifier and Type Field Description int
level
Alpha, beta, release candidate or patch level.VersionNumber.LevelType
levelType
Type of the release: alpha, beta, release candidate or patch.int
major
Major version number.int
micro
Micro version number.static VersionNumber
MIN_VERSION_NUMBER
Minimal version number: 0.0.0-alpha00.int
minor
Minor version number.
-
Constructor Summary
Constructors Constructor Description VersionNumber()
Constructs a minimal version number: 0.0.0-alpha00.VersionNumber(int major, int minor, int micro)
Constructs version number major.minor.micro.VersionNumber(int major, int minor, int micro, int patch)
Constructs version number major.minor.micro_patch.VersionNumber(int major, int minor, int micro, VersionNumber.LevelType levelType, int level)
Constructs version number major.minor.micro (-alpha|-beta|-rc|_)level.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(VersionNumber other)
boolean
equals(Object other)
static VersionNumber
fromString(String s)
Equivalent tofromString(s, false)
.static VersionNumber
fromString(String s, boolean lenient)
Parses specified string as a version number.int
hashCode()
VersionNumber
noLevel()
Returns a copy of this VersionNumber but with all level info (alpha, beta, release candidate, patch) cleared.static void
parse(String s, VersionNumber version)
Parses specified string and returns the result in the specified version number object.String
toString()
Returns a string having the following format: major.minor.micro if this version number is not an alpha, beta, Release candidate or patch release.
-
-
-
Field Detail
-
major
public int major
Major version number. Example: 1 in 1.5.0_06.
-
minor
public int minor
Minor version number. Example: 5 in 1.5.0_06.
-
micro
public int micro
Micro version number. Example: 0 in 1.5.0_06.
-
levelType
public VersionNumber.LevelType levelType
Type of the release: alpha, beta, release candidate or patch.
-
level
public int level
Alpha, beta, release candidate or patch level. Example: 6 in 1.5.0_06.
-
MIN_VERSION_NUMBER
public static final VersionNumber MIN_VERSION_NUMBER
Minimal version number: 0.0.0-alpha00.
-
-
Constructor Detail
-
VersionNumber
public VersionNumber()
Constructs a minimal version number: 0.0.0-alpha00.- See Also:
MIN_VERSION_NUMBER
-
VersionNumber
public VersionNumber(int major, int minor, int micro)
Constructs version number major.minor.micro. Example: 1.1.2.
-
VersionNumber
public VersionNumber(int major, int minor, int micro, int patch)
Constructs version number major.minor.micro_patch. Example: 3.1.0_01.
-
VersionNumber
public VersionNumber(int major, int minor, int micro, VersionNumber.LevelType levelType, int level)
Constructs version number major.minor.micro (-alpha|-beta|-rc|_)level. Example: 3.1.0-beta02.
-
-
Method Detail
-
fromString
public static VersionNumber fromString(String s)
Equivalent tofromString(s, false)
.
-
fromString
public static VersionNumber fromString(String s, boolean lenient)
Parses specified string as a version number.- Parameters:
s
- string to be parsedlenient
- iftrue
, any string starting with "\d+(\.\d+)?(\.\d+)?(_\d+)?
" will be successfully parsed.- Returns:
- parsed version number or
null
if it cannot be parsed.
-
parse
public static void parse(String s, VersionNumber version) throws IllegalArgumentException
Parses specified string and returns the result in the specified version number object.- Parameters:
s
- string to be parsedversion
- the parsed version number is stored in this object- Throws:
IllegalArgumentException
- ifs
cannot be parsed
-
noLevel
public VersionNumber noLevel()
Returns a copy of this VersionNumber but with all level info (alpha, beta, release candidate, patch) cleared.
-
compareTo
public int compareTo(VersionNumber other)
- Specified by:
compareTo
in interfaceComparable<VersionNumber>
-
toString
public String toString()
Returns a string having the following format: major.minor.micro if this version number is not an alpha, beta, Release candidate or patch release. Otherwise, returns a string having the following format: major.minor.micro (-alpha|-beta|-rc|_)level.
-
-