- All Implemented Interfaces:
Comparable<Version>
The version number is represented by the following simplified pattern:
[v]major.minor[.patch][(r.-)build][(-)suffix][(+)suffixVersion]
The version is composed of the following parts:
- major: The major version number
- minor: The minor version number
- patch: The patch or fix version number
- build: The current build number
- suffix: The suffix or pre-release identifier (e.g. alpha, beta, rc, ...)
- suffixVersion: The version of the suffix or pre-release identifier
Everything placed in square brackets is optional.
Characters in parentheses are separators, if there are multiple separators, one of them can be used.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordThis record represents an appendable version number.
The record is used for the build and suffix version numbers.static final classThis class represents a builder for a version number. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Version.AppendingVersionThe appendable build version number.private final intThe major version number.private final intThe minor version number.private final intThe patch or fix version number.private final StringThe suffix or pre-release identifier.private final Version.AppendingVersionThe appendable suffix version number.private static final StringConstant for the system property 'version.default.prefixed'.private static final PatternThe pattern used to parse a version number.
Group 1: The major version number Group 2: The minor version number Group 3: The patch or fix version number Group 6: The build number Group 8: The suffix or pre-release identifier Group 10: The version of the suffix or pre-release identifier The pattern is case-sensitive and allows the version number to be prefixed with a 'v'.static final VersionA constant value for a version number of 0.0.0.
This is the default version number. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVersion(int major, int minor, int patch, @NotNull Version.AppendingVersion buildVersion, @Nullable String suffix, @NotNull Version.AppendingVersion suffixVersion) Constructs a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0. -
Method Summary
Modifier and TypeMethodDescription@NotNull Version.BuilderReturns the version as a builder for modifications.static @NotNull Version.Builderbuilder(int major, int minor) Creates a new version builder with the given version numbers.
The version numbers will be clamped to a minimum of 0.static @NotNull Version.Builderbuilder(int major, int minor, int patch) Creates a new version builder with the given version numbers.
The version numbers will be clamped to a minimum of 0.intCompares this version with the given version.
The comparison is based on the following order:
Major version number Minor version number Patch or fix version number Build version numberbooleanintgetBuild()Returns the build version number as an integer.intgetMajor()Returns the major version number as an integer.intgetMinor()Returns the minor version number as an integer.intgetPatch()Returns the patch or fix version number as an integer.@NotNull StringReturns the suffix or pre-release identifier.intGets the index of the suffix.
The index is used to compare the suffix with other suffixes.
The index is as follows:
0: No or unknown suffix 1: Alpha 2: Beta 3: Release candidate 4: Release 5: FinalintReturns the suffix version number as an integer.inthashCode()static @NotNull Versionof(int major, int minor) Creates a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0.static @NotNull Versionof(int major, int minor, int patch) Creates a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0.static @NotNull VersionParses a version from a string.toString()@NotNull StringtoString(boolean prefixed) Returns the version as a string.
The version will be formatted as follows:@NotNull StringtoString(boolean prefixed, boolean omitZeros) Returns the version as a string.
The version will be formatted as follows:
-
Field Details
-
VERSION_PATTERN
The pattern used to parse a version number.
- Group 1: The major version number
- Group 2: The minor version number
- Group 3: The patch or fix version number
- Group 6: The build number
- Group 8: The suffix or pre-release identifier
- Group 10: The version of the suffix or pre-release identifier
The major and minor version numbers are required.
The patch version is optional.
They must be separated by a dot.
The build number is optional.
It must be separated by a dot, a hyphen, or an 'r' (release).
The suffix and suffix-version are optional.
If the suffix is present, it must be separated by a hyphen.
If the suffix-version is present, it must be separated by a plus sign.
-
VERSION_DEFAULT_PREFIXED
Constant for the system property 'version.default.prefixed'.
If the system property is set to 'true', the version number will be prefixed with a 'v'
when it is converted to a string viatoString().
The system property does not affecttoString(boolean).
The default value is 'true'.
- See Also:
-
ZERO
A constant value for a version number of 0.0.0.
This is the default version number. -
major
private final int majorThe major version number. -
minor
private final int minorThe minor version number. -
patch
private final int patchThe patch or fix version number. -
buildVersion
The appendable build version number. -
suffix
The suffix or pre-release identifier. -
suffixVersion
The appendable suffix version number.
-
-
Constructor Details
-
Version
protected Version(int major, int minor, int patch, @NotNull @NotNull Version.AppendingVersion buildVersion, @Nullable @Nullable String suffix, @NotNull @NotNull Version.AppendingVersion suffixVersion) Constructs a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0.- Parameters:
major- The major version numberminor- The minor version numberpatch- The patch or fix version numberbuildVersion- The appendable build version number, containing the separator and the version numbersuffix- The suffix or pre-release identifiersuffixVersion- The appendable suffix version number, containing the separator and the version number- Throws:
NullPointerException- If the build or suffix version is null
-
-
Method Details
-
of
Creates a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0.
If the version numbers are all 0 or less,
ZEROwill be returned.
- Parameters:
major- The major version numberminor- The minor version number- Returns:
- The created version
- See Also:
-
of
Creates a new version with the given version numbers.
The version numbers will be clamped to a minimum of 0.
If the version numbers are all 0 or less,
ZEROwill be returned.
- Parameters:
major- The major version numberminor- The minor version numberpatch- The patch or fix version number- Returns:
- The created version
- See Also:
-
builder
Creates a new version builder with the given version numbers.
The version numbers will be clamped to a minimum of 0.- Parameters:
major- The major version numberminor- The minor version number- Returns:
- The created version builder
- See Also:
-
builder
Creates a new version builder with the given version numbers.
The version numbers will be clamped to a minimum of 0.- Parameters:
major- The major version numberminor- The minor version numberpatch- The patch or fix version number- Returns:
- The created version builder
- See Also:
-
parse
Parses a version from a string.
If the given string to parse is null, empty, blank,
or does not match the pattern (VERSION_PATTERN),ZEROwill be returned.
The following examples are valid base version strings:
- 1.0
- v1.0
- 1.0.0
- v1.0.0
The major and minor version numbers are required and must be separated by a dot.
The patch version is optional and must be separated by a dot.
The build number is optional and can be separated by a dot, a hyphen, or an 'r' (release).
Examples for valid build version strings are:
- 1.0.0.0
- 1.0.0-0
- 1.0.0r0
Note: If the patch version is not present, the build number must not be separated by a dot
otherwise it will be considered as the patch version.
The suffix and suffix-version are optional.
If the suffix is present, it must be separated by a hyphen.
If the suffix-version is present, it must be separated by a plus sign.
Examples for valid suffix and suffix-version strings are:
- 1.0.0-alpha
- 1.0.0+001
- 1.0.0-alpha+001
- 1.0.0-0+001
- 1.0.0r0-alpha+001
- Parameters:
version- The version string to parse- Returns:
- The parsed version or
ZERO
-
getMajor
public int getMajor()Returns the major version number as an integer.- Returns:
- The major version
-
getMinor
public int getMinor()Returns the minor version number as an integer.- Returns:
- The minor version
-
getPatch
public int getPatch()Returns the patch or fix version number as an integer.- Returns:
- The patch or fix version or
0if not present
-
getBuild
public int getBuild()Returns the build version number as an integer.- Returns:
- The build version or
0if not present
-
getSuffix
Returns the suffix or pre-release identifier.- Returns:
- The suffix or pre-release identifier or an empty string if not present
-
getSuffixIndex
public int getSuffixIndex()Gets the index of the suffix.
The index is used to compare the suffix with other suffixes.
The index is as follows:
- 0: No or unknown suffix
- 1: Alpha
- 2: Beta
- 3: Release candidate
- 4: Release
- 5: Final
- Returns:
- The index of the suffix
-
getSuffixVersion
public int getSuffixVersion()Returns the suffix version number as an integer.- Returns:
- The suffix version or
0if not present
-
asBuilder
Returns the version as a builder for modifications.- Returns:
- The version as a builder
-
compareTo
Compares this version with the given version.
The comparison is based on the following order:
- Major version number
- Minor version number
- Patch or fix version number
- Build version number
If the suffixes are equal, the suffix version will be compared.
If the suffixes are not equal, the suffixes will be compared
in this case, the suffix version will not be considered.
The suffixes are compared based on the following order:
- Alpha
- Beta
- Release candidate
- Release
- Final
The first comparison that is not equal will determine the result.
- Specified by:
compareToin interfaceComparable<Version>- Parameters:
o- The version to compare with- Returns:
- The comparison result, negative if this version is less than the given version,
positive if this version is greater than the given version, and zero if both versions are equal
-
equals
-
hashCode
public int hashCode() -
toString
-
toString
Returns the version as a string.
The version will be formatted as follows:
If the patch version is 0, it will be omitted.<major>.<minor>.<patch>[(r.-)<build>][-<suffix>][+<suffixVersion>]- Parameters:
prefixed- If the version should be prefixed with a 'v'- Returns:
- The version as a string
- See Also:
-
toString
Returns the version as a string.
The version will be formatted as follows:
If the patch version is 0 and<major>.<minor>.<patch>[(r.-)<build>][-<suffix>][+<suffixVersion>]omitZerosis true, it will be omitted.
In this case, the version will be formatted as follows:
<major>.<minor>[(r.-)<build>][-<suffix>][+<suffixVersion>]- Parameters:
prefixed- If the version should be prefixed with a 'v'omitZeros- If the patch version should be omitted if it is 0- Returns:
- The version as a string
-