public final class Version extends Object implements Serializable, Comparable<Version>
MAJOR.MINOR.PATCH[QUALIFIER] where the qualifier is optional and can have an
extra version.
For example: 1.2.0.RC1 is the first release candidate of 1.2.0 and
1.5.0-M4 is the fourth milestone of 1.5.0. The special RELEASE
qualifier indicates a final release (a.k.a. GA).
Two formats are currently supported, Version.Format.V1 that uses a dot to separate the
qualifier from the version itself and Version.Format.V2 that is SemVer compliant (and
therefore uses a dash to separate the qualifier).
The main purpose of parsing a version is to compare it with another version.
| Modifier and Type | Class and Description |
|---|---|
static class |
Version.Format
Define the supported version format.
|
static class |
Version.Qualifier
A version qualifier.
|
| Constructor and Description |
|---|
Version(Integer major,
Integer minor,
Integer patch,
Version.Qualifier qualifier) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Version other) |
boolean |
equals(Object obj) |
Version |
format(Version.Format format)
Format this version to the specified
Version.Format. |
Version.Format |
getFormat() |
Integer |
getMajor() |
Integer |
getMinor() |
Integer |
getPatch() |
Version.Qualifier |
getQualifier() |
int |
hashCode() |
static Version |
parse(String text)
Parse the string representation of a
Version. |
static Version |
safeParse(String text)
Parse safely the specified string representation of a
Version. |
String |
toString() |
public Version(Integer major, Integer minor, Integer patch, Version.Qualifier qualifier)
public Version format(Version.Format format)
Version.Format.format - the format to usepublic Integer getMajor()
public Integer getMinor()
public Integer getPatch()
public Version.Qualifier getQualifier()
public Version.Format getFormat()
public static Version parse(String text)
Version. Throws an
InvalidVersionException if the version could not be parsed.text - the version textInvalidVersionException - if the version text could not be parsedVersionParserpublic static Version safeParse(String text)
Version.
Return null if the text represents an invalid version.
text - the version textVersionParserpublic int compareTo(Version other)
compareTo in interface Comparable<Version>Copyright © 2021 Pivotal Software, Inc.. All rights reserved.