public class Version extends Object implements Comparable<Version>, Serializable
version
of a piece of software.
A version String
has the following form:
major
"."minor
"."
release
["."patchLevel
]["-"suffix
]
The suffix may consist of 'a-zA-Z0-9#$!_-'. Additionally the following version string is
also valid: '
1.2.3.test'.
Examples of valid versions are:
1.2.3
1.2.3.4
1.2.3.4-test
1.2.3-t_e!st
Instances of this class are immutable!
compareTo(Version)
understands the SNAPSHOT_SUFFIX
. This means:
1.0.0-SNAPSHOT < 1.0.0
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_SEPARATOR |
static Version |
MAX_VERSION
The maximum Version possible.
|
static Version |
MIN_VERSION
The minimum Version that can exist.
|
static String |
SNAPSHOT_SUFFIX |
static String |
SUFFIX_SEPARATOR |
static Pattern |
validityCheck
A regex that is used to check the suffix for valid characters.
|
Constructor and Description |
---|
Version(int major,
int minor,
int release,
int patchLevel) |
Version(int major,
int minor,
int release,
int patchLevel,
String suffix) |
Version(String versionStr)
Creates a new instance from the given
versionStr . |
Modifier and Type | Method and Description |
---|---|
Version |
changeMajor(int major) |
Version |
changeMinor(int minor) |
Version |
changePatchLevel(int patchLevel) |
Version |
changeRelease(int release) |
Version |
changeSuffix(String suffix) |
int |
compareTo(Version other)
Compares this
Version object to another one. |
boolean |
equals(Object other) |
int |
getMajor() |
int |
getMinor() |
int |
getPatchLevel() |
int |
getRelease() |
String |
getSuffix() |
int |
hashCode() |
String |
toString()
|
public static final String SNAPSHOT_SUFFIX
public static final Version MIN_VERSION
public static final Version MAX_VERSION
public static final String DEFAULT_SEPARATOR
public static final String SUFFIX_SEPARATOR
public static Pattern validityCheck
public Version(String versionStr) throws MalformedVersionException
versionStr
.versionStr
- the version encoded as a String.MalformedVersionException
public Version(int major, int minor, int release, int patchLevel)
major
- minor
- release
- patchLevel
- public int getMajor()
public Version changeMajor(int major)
major
- The major with which to create a new Version.public int getMinor()
public Version changeMinor(int minor)
minor
- The minor with which to create a new Version.public int getPatchLevel()
public Version changePatchLevel(int patchLevel)
patchLevel
- The patchLevel with which to create a new Version.public int getRelease()
public Version changeRelease(int release)
release
- The release
with which to create a new Version.release
.public Version changeSuffix(String suffix)
suffix
- The suffix
with which to create a new Version.suffix
.public int compareTo(Version other)
Version
object to another one.
A version is considered to be less than another version if its major component is less than the other version's major component, or the major components are equal and its minor component is less than the other version's minor component, or the major and minor components are equal and its release component is less than the other version's release component. The suffix is not relevant for the natural ordering of Versions, though for equality.
Note: Given two version v1,v2
and v1.compareTo(Version v2) = 0
,
this does not imply that v1
and v2
are equal according to equals!
A version is considered to be equal to another version if the
major, minor and micro components are equal and the qualifier component
is equal (see equals(Object)
).
compareTo
in interface Comparable<Version>
other
- The Version
object to be compared.Version
object.Copyright © 2013–2019. All rights reserved.