- All Implemented Interfaces:
Serializable
,Comparable<Version>
The Version
class is immutable and thread-safe.
- Since:
- 0.1.0
- Author:
- Zafar Khaja <zafarkhaja@gmail.com>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A mutable builder for the immutableVersion
class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator
<Version> Deprecated.static final Comparator
<Version> A comparator that sorts versions in increment order, from lowest to highest.static final Comparator
<Version> A comparator that sorts versions in (highest) precedence order. -
Method Summary
Modifier and TypeMethodDescriptionReturns thisVersion
's build metadata in the form of dot-separated identifiers.int
Compares versions, along with their build metadata.int
Compares versions, ignoring their build metadata.int
compareWithBuildsTo
(Version other) Deprecated.forRemoval since 0.10.0, usecompareTo(Version)
boolean
Checks if thisVersion
exactly equals the specifiedVersion
.static Version
forIntegers
(int major) Deprecated.forRemoval since 0.10.0, useof(long)
static Version
forIntegers
(int major, int minor) Deprecated.forRemoval since 0.10.0, useof(long, long)
static Version
forIntegers
(int major, int minor, int patch) Deprecated.forRemoval since 0.10.0, useof(long, long, long)
Deprecated.forRemoval since 0.10.0, usebuildMetadata()
int
Deprecated.forRemoval since 0.10.0, usemajorVersion()
int
Deprecated.forRemoval since 0.10.0, useminorVersion()
Deprecated.forRemoval since 0.10.0int
Deprecated.forRemoval since 0.10.0, usepatchVersion()
Deprecated.forRemoval since 0.10.0, usepreReleaseVersion()
boolean
greaterThan
(Version other) Deprecated.forRemoval since 0.10.0, useisHigherThan(Version)
boolean
greaterThanOrEqualTo
(Version other) Deprecated.forRemoval since 0.10.0, useisHigherThanOrEquivalentTo(Version)
int
hashCode()
Deprecated.forRemoval since 0.10.0Deprecated.forRemoval since 0.10.0, usenextMajorVersion(String...)
incrementMajorVersion
(String preRelease) Deprecated.forRemoval since 0.10.0, usenextMajorVersion(String...)
Deprecated.forRemoval since 0.10.0, usenextMinorVersion(String...)
incrementMinorVersion
(String preRelease) Deprecated.forRemoval since 0.10.0, usenextMinorVersion(String...)
Deprecated.forRemoval since 0.10.0, usenextPatchVersion(String...)
incrementPatchVersion
(String preRelease) Deprecated.forRemoval since 0.10.0, usenextPatchVersion(String...)
Deprecated.forRemoval since 0.10.0, usenextPreReleaseVersion(String...)
boolean
isEquivalentTo
(Version other) Determines if thisVersion
has the same precedence as the specifiedVersion
.boolean
isHigherThan
(Version other) Determines if thisVersion
has a higher precedence compared with the specifiedVersion
.boolean
Determines if thisVersion
has a higher or equal precedence compared with the specifiedVersion
.boolean
isLowerThan
(Version other) Determines if thisVersion
has a lower precedence compared with the specifiedVersion
.boolean
isLowerThanOrEquivalentTo
(Version other) Determines if thisVersion
has a lower or equal precedence compared with the specifiedVersion
.boolean
Checks if thisVersion
represents a pre-release version.boolean
isPublicApiCompatibleWith
(Version other) Checks if thisVersion
is compatible with the specifiedVersion
in terms of their public API.boolean
Checks if thisVersion
represents a stable public API.boolean
isSameMajorVersionAs
(Version other) Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major versions.boolean
isSameMinorVersionAs
(Version other) Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major and minor versions.boolean
isSamePatchVersionAs
(Version other) Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major, minor and patch versions.boolean
isStable()
Checks if thisVersion
represents a stable version.static boolean
Checks validity of the specified SemVer version string in strict mode, which ensures full compliance with the specification.static boolean
Checks validity of the specified SemVer version string.boolean
Deprecated.forRemoval since 0.10.0, useisLowerThan(Version)
boolean
lessThanOrEqualTo
(Version other) Deprecated.forRemoval since 0.10.0, useisLowerThanOrEquivalentTo(Version)
long
Returns thisVersion
's major version.long
Returns thisVersion
's minor version.nextMajorVersion
(long major, String... preReleaseIds) Obtains the nextVersion
of the specified major version number, with an optional pre-release version label.nextMajorVersion
(String... preReleaseIds) Obtains the nextVersion
by incrementing the major version number by one, with an optional pre-release version label.nextMinorVersion
(long minor, String... preReleaseIds) Obtains the nextVersion
of the specified minor version number, with an optional pre-release version label.nextMinorVersion
(String... preReleaseIds) Obtains the nextVersion
by incrementing the minor version number by one, with an optional pre-release version label.nextPatchVersion
(long patch, String... preReleaseIds) Obtains the nextVersion
of the specified patch version number, with an optional pre-release version label.nextPatchVersion
(String... preReleaseIds) Obtains the nextVersion
by incrementing the patch version number by one, with an optional pre-release version label.nextPreReleaseVersion
(String... ids) Obtains the nextVersion
by incrementing or replacing the pre-release version.static Version
of
(long major) Obtains aVersion
instance of the specified major version.static Version
of
(long major, long minor) Obtains aVersion
instance of the specified major and minor versions.static Version
of
(long major, long minor, long patch) Obtains aVersion
instance of the specified major, minor and patch versions.static Version
Obtains aVersion
instance of the specified major, minor, patch and pre-release versions.static Version
Obtains aVersion
instance of the specified major, minor, patch and pre-release versions, as well as build metadata.static Version
Obtains aVersion
instance of the specified major, minor and pre-release versions.static Version
Obtains aVersion
instance of the specified major, minor and pre-release versions, as well as build metadata.static Version
Obtains aVersion
instance of the specified major and pre-release versions.static Version
Obtains aVersion
instance of the specified major and pre-release versions, as well as build metadata.static Version
Obtains aVersion
instance by parsing the specified string in strict mode, which ensures full compliance with the specification.static Version
Obtains aVersion
instance by parsing the specified string.long
Returns thisVersion
's patch version.Returns thisVersion
's pre-release version in the form of dot-separated identifiers.boolean
Checks if thisVersion
satisfies the specified range expression.boolean
Checks if thisVersion
satisfies the specified predicate.setBuildMetadata
(String build) Deprecated.forRemoval since 0.10.0, usewithBuildMetadata(String...)
setPreReleaseVersion
(String preRelease) Deprecated.forRemoval since 0.10.0, consider usingnextPreReleaseVersion(String...)
Converts thisVersion
toBuilder
.Obtains the nextVersion
by dropping the pre-release version.toString()
Tries to obtain aVersion
instance by parsing the specified string in strict mode, which ensures full compliance with the specification.Tries to obtain aVersion
instance by parsing the specified string.static Version
Deprecated.forRemoval since 0.10.0, useparse(String)
withBuildMetadata
(String... ids) Obtains a newVersion
with the specified build identifiers.Obtains a (new)Version
without build metadata.
-
Field Details
-
INCREMENT_ORDER
A comparator that sorts versions in increment order, from lowest to highest.The comparator is intended for use in comparison-based data structures.
- Since:
- 0.10.0
- See Also:
-
PRECEDENCE_ORDER
A comparator that sorts versions in (highest) precedence order.The ordering imposed by this comparator is reverse of the "natural" increment ordering, that is, versions are arranged in descending order from highest-precedence to lowest-precedence.
The comparator is intended for use in comparison-based data structures.
- Since:
- 0.10.0
- See Also:
-
BUILD_AWARE_ORDER
Deprecated.forRemoval since 0.10.0, usecompareTo(Version)
-
-
Method Details
-
parse
Obtains aVersion
instance by parsing the specified string in strict mode, which ensures full compliance with the specification.- Parameters:
version
- a string representing a SemVer version, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifversion
is nullParseException
- ifversion
can't be parsed- Since:
- 0.10.0
- See Also:
-
parse
Obtains aVersion
instance by parsing the specified string.This method provides a way to parse the specified string in lenient mode, which accepts shorter version cores, such as "1" or "1.2".
- Parameters:
version
- a string representing a SemVer version, non-nullstrictly
- whether to parse the specified string in strict mode- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifversion
is nullParseException
- ifversion
can't be parsed- Since:
- 0.10.0
- See Also:
-
tryParse
Tries to obtain aVersion
instance by parsing the specified string in strict mode, which ensures full compliance with the specification.- Parameters:
version
- a string representing a SemVer version, nullable- Returns:
- an
Optional
with aVersion
instance, if the specified string can be parsed; emptyOptional
otherwise - Since:
- 0.10.0
- See Also:
-
tryParse
Tries to obtain aVersion
instance by parsing the specified string.This method provides a way to parse the specified string in lenient mode, which accepts shorter version cores, such as "1" or "1.2".
- Parameters:
version
- a string representing a SemVer version, nullablestrictly
- whether to parse the specified string in strict mode- Returns:
- an
Optional
with aVersion
instance, if the specified string can be parsed; emptyOptional
otherwise - Since:
- 0.10.0
- See Also:
-
isValid
Checks validity of the specified SemVer version string in strict mode, which ensures full compliance with the specification.Note that internally this method makes use of
parse(String)
and suppresses any exceptions, so using it to avoid dealing with exceptions like so:
would mean parsing the same version string twice. In this case, as an alternative, consider usingString version = "1.2.3"; if (Version.isValid(version)) { Version v = Version.parse(version); }
tryParse(String)
.- Parameters:
version
- a string representing a SemVer version, nullable- Returns:
true
, if the specified string is a valid SemVer version;false
otherwise- Since:
- 0.10.0
- See Also:
-
isValid
Checks validity of the specified SemVer version string.This method provides a way to parse the specified string in lenient mode, which accepts shorter version cores, such as "1" or "1.2".
- Parameters:
version
- a string representing a SemVer version, nullablestrictly
- whether to parse the specified string in strict mode- Returns:
true
, if the specified string is a valid SemVer version;false
otherwise- Since:
- 0.10.0
- See Also:
-
of
Obtains aVersion
instance of the specified major version.- Parameters:
major
- a major version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
is negative- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major and pre-release versions.- Parameters:
major
- a major version number, non-negativepreRelease
- a pre-release version label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
is negativeParseException
- ifpreRelease
can't be parsed- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major and pre-release versions, as well as build metadata.- Parameters:
major
- a major version number, non-negativepreRelease
- a pre-release version label, nullablebuild
- a build metadata label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
is negativeParseException
- ifpreRelease
orbuild
can't be parsed- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major and minor versions.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
orminor
is negative- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major, minor and pre-release versions.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepreRelease
- a pre-release version label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
orminor
is negativeParseException
- ifpreRelease
can't be parsed- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major, minor and pre-release versions, as well as build metadata.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepreRelease
- a pre-release version label, nullablebuild
- a build metadata label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
orminor
is negativeParseException
- ifpreRelease
orbuild
can't be parsed- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major, minor and patch versions.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepatch
- a patch version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- if any of the arguments is negative- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major, minor, patch and pre-release versions.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepatch
- a patch version number, non-negativepreRelease
- a pre-release version label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- if any of the numeric arguments is negativeParseException
- ifpreRelease
can't be parsed- Since:
- 0.10.0
-
of
Obtains aVersion
instance of the specified major, minor, patch and pre-release versions, as well as build metadata.- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepatch
- a patch version number, non-negativepreRelease
- a pre-release version label, nullablebuild
- a build metadata label, nullable- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- if any of the numeric arguments is negativeParseException
- ifpreRelease
orbuild
can't be parsed- Since:
- 0.10.0
-
majorVersion
public long majorVersion()Returns thisVersion
's major version.- Returns:
- the major version number
- Since:
- 0.10.0
-
minorVersion
public long minorVersion()Returns thisVersion
's minor version.- Returns:
- the minor version number
- Since:
- 0.10.0
-
patchVersion
public long patchVersion()Returns thisVersion
's patch version.- Returns:
- the patch version number
- Since:
- 0.10.0
-
preReleaseVersion
Returns thisVersion
's pre-release version in the form of dot-separated identifiers.- Returns:
- the pre-release version label, if present
- Since:
- 0.10.0
-
buildMetadata
Returns thisVersion
's build metadata in the form of dot-separated identifiers.- Returns:
- the build metadata label, if present
- Since:
- 0.10.0
-
nextMajorVersion
Obtains the nextVersion
by incrementing the major version number by one, with an optional pre-release version label.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
preReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the major version number overflowsIllegalArgumentException
- ifpreReleaseIds
is null or contains nullParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextMajorVersion
Obtains the nextVersion
of the specified major version number, with an optional pre-release version label.The specified major version number must be higher than this
Version
's major version.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
major
- the next major version number, non-negativepreReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
is negative, or ifpreReleaseIds
is null or contains nullIllegalStateException
- ifmajor
is lower than or equivalent to thisVersion
's major versionParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextMinorVersion
Obtains the nextVersion
by incrementing the minor version number by one, with an optional pre-release version label.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
preReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the minor version number overflowsIllegalArgumentException
- ifpreReleaseIds
is null or contains nullParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextMinorVersion
Obtains the nextVersion
of the specified minor version number, with an optional pre-release version label.The specified minor version number must be higher than this
Version
's minor version.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
minor
- the next minor version number, non-negativepreReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifminor
is negative, or ifpreReleaseIds
is null or contains nullIllegalStateException
- ifminor
is lower than or equivalent to thisVersion
's minor versionParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextPatchVersion
Obtains the nextVersion
by incrementing the patch version number by one, with an optional pre-release version label.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
preReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the patch version number overflowsIllegalArgumentException
- ifpreReleaseIds
is null or contains nullParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextPatchVersion
Obtains the nextVersion
of the specified patch version number, with an optional pre-release version label.The specified patch version number must be higher than this
Version
's patch version.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
patch
- the next patch version number, non-negativepreReleaseIds
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifpatch
is negative, or ifpreReleaseIds
is null or contains nullIllegalStateException
- ifpatch
is lower than or equivalent to thisVersion
's patch versionParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
nextPreReleaseVersion
Obtains the nextVersion
by incrementing or replacing the pre-release version.If no pre-release identifiers are specified, the current pre-release version's last numeric identifier is incremented. If the current pre-release version's last identifier is not numeric, a new numeric identifier of value "0" is appended for this operation. If specified, however, the pre-release identifiers replace the current pre-release version. The new pre-release version must be higher than this
Version
's pre-release version.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
This method drops the build metadata, if present.
- Parameters:
ids
- zero or more pre-release identifiers, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the incremented numeric identifier overflowsIllegalArgumentException
- ifids
is null or contains nullIllegalStateException
- if invoked on a stableVersion
, or if the specified pre-release version is lower than or equivalent to thisVersion
's pre-release versionParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
toStableVersion
Obtains the nextVersion
by dropping the pre-release version.This method drops the build metadata, if present.
- Returns:
- a
Version
instance - Since:
- 0.10.0
-
withBuildMetadata
Obtains a newVersion
with the specified build identifiers.Multiple identifiers can be specified in a single argument joined with dots, or in separate arguments, or both.
- Parameters:
ids
- one or more build identifiers, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifids
is null/empty or contains nullParseException
- if any of the specified identifiers can't be parsed- Since:
- 0.10.0
-
withoutBuildMetadata
Obtains a (new)Version
without build metadata.- Returns:
- a
Version
instance - Since:
- 0.10.0
-
satisfies
Checks if thisVersion
satisfies the specified predicate.- Parameters:
predicate
- a predicate to test, non-null- Returns:
true
, if thisVersion
satisfies the predicate;false
otherwise- Throws:
IllegalArgumentException
- ifpredicate
is null- Since:
- 0.10.0
-
satisfies
Checks if thisVersion
satisfies the specified range expression.- Parameters:
expr
- a SemVer Expression string, non-null- Returns:
true
, if thisVersion
satisfies the specified expression;false
otherwise- Throws:
IllegalArgumentException
- ifexpr
is nullParseException
- ifexpr
can't be parsed- Since:
- 0.7.0
-
isPreRelease
public boolean isPreRelease()Checks if thisVersion
represents a pre-release version.This method is opposite of
isStable()
.- Returns:
true
, if thisVersion
represents a pre-release version;false
otherwise- Since:
- 0.10.0
- See Also:
-
isStable
public boolean isStable()Checks if thisVersion
represents a stable version.Pre-release versions are considered unstable. (SemVer p.9)
- Returns:
true
, if thisVersion
represents a stable version;false
otherwise- Since:
- 0.10.0
- See Also:
-
isPublicApiStable
public boolean isPublicApiStable()Checks if thisVersion
represents a stable public API.Versions lower than 1.0.0 are for initial development, therefore the public API should not be considered stable. (SemVer p.4)
- Returns:
true
, if thisVersion
represents a stable public API;false
otherwise- Since:
- 0.10.0
-
isPublicApiCompatibleWith
Checks if thisVersion
is compatible with the specifiedVersion
in terms of their public API.Two versions are compatible in terms of public API iff they have the same major version of 1 or higher. Being public API compatible doesn't necessarily mean both versions have the same set of public API units. It only means that the versions are interchangeable.
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if the versions are compatible in terms of public API;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
-
isSameMajorVersionAs
Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major versions.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if both versions have the same major version;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
-
isSameMinorVersionAs
Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major and minor versions.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if both versions have the same major and minor versions;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
-
isSamePatchVersionAs
Checks if thisVersion
is compatible with the specifiedVersion
in terms of their major, minor and patch versions.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if both versions have the same major, minor and patch versions;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
-
isHigherThan
Determines if thisVersion
has a higher precedence compared with the specifiedVersion
.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is higher than the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
- See Also:
-
isHigherThanOrEquivalentTo
Determines if thisVersion
has a higher or equal precedence compared with the specifiedVersion
.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is higher than or equivalent to the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
- See Also:
-
isLowerThan
Determines if thisVersion
has a lower precedence compared with the specifiedVersion
.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is lower than the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
- See Also:
-
isLowerThanOrEquivalentTo
Determines if thisVersion
has a lower or equal precedence compared with the specifiedVersion
.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is lower than or equivalent to the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
- See Also:
-
isEquivalentTo
Determines if thisVersion
has the same precedence as the specifiedVersion
.As per SemVer p.10, build metadata is ignored when determining version precedence. To test for exact equality, including build metadata, use
equals(Object)
.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is equivalent to the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
- See Also:
-
compareTo
Compares versions, along with their build metadata.Note that this method violates the SemVer p.10 ("build metadata must be ignored") rule, hence can't be used for determining version precedence. It was made so intentionally for it to be consistent with
equals
as defined byComparable
, and to be used in comparison-based data structures.As the Specification defines no comparison rules for build metadata, this behavior is strictly implementation-defined. Build metadata are compared similarly to pre-release versions. A version with build metadata is ordered after an equivalent one without it.
To compare Versions without their build metadata in order to determine precedence use
compareToIgnoreBuildMetadata(Version)
.- Specified by:
compareTo
in interfaceComparable<Version>
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
- a negative integer, zero or a positive integer if this
Version
is less than, equal to or greater than the specifiedVersion
- Throws:
IllegalArgumentException
- ifother
is null
-
compareToIgnoreBuildMetadata
Compares versions, ignoring their build metadata.This method adheres to the comparison rules defined by the Specification, and as such can be used for determining version precedence, either as a natural-order comparator (
Version::compareToIgnoreBuildMetadata
), or as a regular method.- Parameters:
other
- theVersion
to compare with, non-null- Returns:
- a negative integer, zero or a positive integer if this
Version
is lower than, equivalent to or higher than the specifiedVersion
- Throws:
IllegalArgumentException
- ifother
is null- Since:
- 0.10.0
-
equals
Checks if thisVersion
exactly equals the specifiedVersion
.Although primarily intended for use in hash-based data structures, it can be used for testing for exact equality, including build metadata, if needed. To test for equivalence use
isEquivalentTo(Version)
. -
hashCode
public int hashCode() -
toString
-
toBuilder
Converts thisVersion
toBuilder
.This method allows to use an instance of
Version
as a template for new instances.- Returns:
- a
Builder
instance populated with values from thisVersion
- Since:
- 0.10.0
-
valueOf
Deprecated.forRemoval since 0.10.0, useparse(String)
- Parameters:
version
- a string representing a SemVer version, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifversion
is nullParseException
- ifversion
can't be parsed
-
forIntegers
Deprecated.forRemoval since 0.10.0, useof(long)
- Parameters:
major
- a major version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
is negative
-
forIntegers
Deprecated.forRemoval since 0.10.0, useof(long, long)
- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifmajor
orminor
is negative
-
forIntegers
Deprecated.forRemoval since 0.10.0, useof(long, long, long)
- Parameters:
major
- a major version number, non-negativeminor
- a minor version number, non-negativepatch
- a patch version number, non-negative- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- if any of the arguments is negative
-
getNormalVersion
Deprecated.forRemoval since 0.10.0- Returns:
- the version core of this
Version
-
getMajorVersion
Deprecated.forRemoval since 0.10.0, usemajorVersion()
- Returns:
- the major version number
-
getMinorVersion
Deprecated.forRemoval since 0.10.0, useminorVersion()
- Returns:
- the minor version number
-
getPatchVersion
Deprecated.forRemoval since 0.10.0, usepatchVersion()
- Returns:
- the patch version number
-
getPreReleaseVersion
Deprecated.forRemoval since 0.10.0, usepreReleaseVersion()
- Returns:
- the pre-release version label, if present; empty string otherwise
-
getBuildMetadata
Deprecated.forRemoval since 0.10.0, usebuildMetadata()
- Returns:
- the build metadata label, if present; empty string otherwise
-
setPreReleaseVersion
Deprecated.forRemoval since 0.10.0, consider usingnextPreReleaseVersion(String...)
- Parameters:
preRelease
- the pre-release version label, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifpreRelease
is nullParseException
- ifpreRelease
can't be parsed
-
setBuildMetadata
Deprecated.forRemoval since 0.10.0, usewithBuildMetadata(String...)
- Parameters:
build
- the build metadata label, non-null- Returns:
- a
Version
instance - Throws:
IllegalArgumentException
- ifbuild
is nullParseException
- ifbuild
can't be parsed
-
incrementMajorVersion
Deprecated.forRemoval since 0.10.0, usenextMajorVersion(String...)
- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the major version number overflows
-
incrementMajorVersion
Deprecated.forRemoval since 0.10.0, usenextMajorVersion(String...)
- Parameters:
preRelease
- the pre-release version label, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the major version number overflowsIllegalArgumentException
- ifpreRelease
is nullParseException
- ifpreRelease
can't be parsed
-
incrementMinorVersion
Deprecated.forRemoval since 0.10.0, usenextMinorVersion(String...)
- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the minor version number overflows
-
incrementMinorVersion
Deprecated.forRemoval since 0.10.0, usenextMinorVersion(String...)
- Parameters:
preRelease
- the pre-release version label, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the minor version number overflowsIllegalArgumentException
- ifpreRelease
is nullParseException
- ifpreRelease
can't be parsed
-
incrementPatchVersion
Deprecated.forRemoval since 0.10.0, usenextPatchVersion(String...)
- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the patch version number overflows
-
incrementPatchVersion
Deprecated.forRemoval since 0.10.0, usenextPatchVersion(String...)
- Parameters:
preRelease
- the pre-release version label, non-null- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the patch version number overflowsIllegalArgumentException
- ifpreRelease
is nullParseException
- ifpreRelease
can't be parsed
-
incrementPreReleaseVersion
Deprecated.forRemoval since 0.10.0, usenextPreReleaseVersion(String...)
- Returns:
- a
Version
instance - Throws:
ArithmeticException
- if the incremented numeric identifier overflowsIllegalStateException
- if invoked on a stableVersion
-
incrementBuildMetadata
Deprecated.forRemoval since 0.10.0- Returns:
- a
Version
instance - Throws:
IllegalStateException
- if thisVersion
doesn't have build metadata
-
greaterThan
Deprecated.forRemoval since 0.10.0, useisHigherThan(Version)
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is higher than the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null
-
greaterThanOrEqualTo
Deprecated.forRemoval since 0.10.0, useisHigherThanOrEquivalentTo(Version)
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is higher than or equivalent to the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null
-
lessThan
Deprecated.forRemoval since 0.10.0, useisLowerThan(Version)
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is lower than the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null
-
lessThanOrEqualTo
Deprecated.forRemoval since 0.10.0, useisLowerThanOrEquivalentTo(Version)
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
true
, if thisVersion
is lower than or equivalent to the otherVersion
;false
otherwise- Throws:
IllegalArgumentException
- ifother
is null
-
compareWithBuildsTo
Deprecated.forRemoval since 0.10.0, usecompareTo(Version)
- Parameters:
other
- theVersion
to compare with, non-null- Returns:
- a negative integer, zero or a positive integer if this
Version
is less than, equal to or greater than the specifiedVersion
- Throws:
IllegalArgumentException
- ifother
is null
-
compareTo(Version)