public class Version extends java.lang.Object implements java.lang.Comparable<Version>
Version class is the main class of the Java SemVer library.
This class implements the Facade design pattern.
It is also immutable, which makes the class thread-safe.| Modifier and Type | Class and Description |
|---|---|
static class |
Version.Builder
A mutable builder for the immutable
Version class. |
| Modifier and Type | Field and Description |
|---|---|
static java.util.Comparator<Version> |
BUILD_AWARE_ORDER
A comparator that respects the build metadata when comparing versions.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Version other)
Compares this version to the other version.
|
int |
compareWithBuildsTo(Version other)
Compare this version to the other version
taking into account the build metadata.
|
boolean |
equals(java.lang.Object other)
Checks if this version equals the other version.
|
static Version |
forIntegers(int major)
Creates a new instance of
Version
for the specified version numbers. |
static Version |
forIntegers(int major,
int minor)
Creates a new instance of
Version
for the specified version numbers. |
static Version |
forIntegers(int major,
int minor,
int patch)
Creates a new instance of
Version
for the specified version numbers. |
java.lang.String |
getBuildMetadata()
Returns the string representation of the build metadata.
|
int |
getMajorVersion()
Returns the major version number.
|
int |
getMinorVersion()
Returns the minor version number.
|
java.lang.String |
getNormalVersion()
Returns the string representation of the normal version.
|
int |
getPatchVersion()
Returns the patch version number.
|
java.lang.String |
getPreReleaseVersion()
Returns the string representation of the pre-release version.
|
boolean |
greaterThan(Version other)
Checks if this version is greater than the other version.
|
boolean |
greaterThanOrEqualTo(Version other)
Checks if this version is greater than or equal to the other version.
|
int |
hashCode() |
Version |
incrementBuildMetadata()
Increments the build metadata.
|
Version |
incrementMajorVersion()
Increments the major version.
|
Version |
incrementMajorVersion(java.lang.String preRelease)
Increments the major version and appends the pre-release version.
|
Version |
incrementMinorVersion()
Increments the minor version.
|
Version |
incrementMinorVersion(java.lang.String preRelease)
Increments the minor version and appends the pre-release version.
|
Version |
incrementPatchVersion()
Increments the patch version.
|
Version |
incrementPatchVersion(java.lang.String preRelease)
Increments the patch version and appends the pre-release version.
|
Version |
incrementPreReleaseVersion()
Increments the pre-release version.
|
boolean |
lessThan(Version other)
Checks if this version is less than the other version.
|
boolean |
lessThanOrEqualTo(Version other)
Checks if this version is less than or equal to the other version.
|
boolean |
satisfies(Expression expr)
Checks if this version satisfies the specified SemVer Expression.
|
boolean |
satisfies(java.lang.String expr)
Checks if this version satisfies the specified SemVer Expression string.
|
Version |
setBuildMetadata(java.lang.String build)
Sets the build metadata.
|
Version |
setPreReleaseVersion(java.lang.String preRelease)
Sets the pre-release version.
|
java.lang.String |
toString() |
static Version |
valueOf(java.lang.String version)
Creates a new instance of
Version as a
result of parsing the specified version string. |
public static final java.util.Comparator<Version> BUILD_AWARE_ORDER
public static Version valueOf(java.lang.String version)
Version as a
result of parsing the specified version string.version - the version string to parseVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic static Version forIntegers(int major)
Version
for the specified version numbers.major - the major version numberVersion classjava.lang.IllegalArgumentException - if a negative integer is passedpublic static Version forIntegers(int major, int minor)
Version
for the specified version numbers.major - the major version numberminor - the minor version numberVersion classjava.lang.IllegalArgumentException - if a negative integer is passedpublic static Version forIntegers(int major, int minor, int patch)
Version
for the specified version numbers.major - the major version numberminor - the minor version numberpatch - the patch version numberVersion classjava.lang.IllegalArgumentException - if a negative integer is passedpublic boolean satisfies(java.lang.String expr)
expr - the SemVer Expression stringtrue if this version satisfies the specified
SemVer Expression or false otherwiseParseException - in case of a general parse errorLexerException - when encounters an illegal characterUnexpectedTokenException - when comes across an unexpected tokenpublic boolean satisfies(Expression expr)
expr - the SemVer Expressiontrue if this version satisfies the specified
SemVer Expression or false otherwisepublic Version incrementMajorVersion()
Version classpublic Version incrementMajorVersion(java.lang.String preRelease)
preRelease - the pre-release version to appendVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic Version incrementMinorVersion()
Version classpublic Version incrementMinorVersion(java.lang.String preRelease)
preRelease - the pre-release version to appendVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic Version incrementPatchVersion()
Version classpublic Version incrementPatchVersion(java.lang.String preRelease)
preRelease - the pre-release version to appendVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic Version incrementPreReleaseVersion()
Version classpublic Version incrementBuildMetadata()
Version classpublic Version setPreReleaseVersion(java.lang.String preRelease)
preRelease - the pre-release version to setVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic Version setBuildMetadata(java.lang.String build)
build - the build metadata to setVersion classjava.lang.IllegalArgumentException - if the input string is NULL or emptyParseException - when invalid version string is providedUnexpectedCharacterException - is a special case of ParseExceptionpublic int getMajorVersion()
public int getMinorVersion()
public int getPatchVersion()
public java.lang.String getNormalVersion()
public java.lang.String getPreReleaseVersion()
public java.lang.String getBuildMetadata()
public boolean greaterThan(Version other)
other - the other version to compare totrue if this version is greater than the other version
or false otherwisecompareTo(Version other)public boolean greaterThanOrEqualTo(Version other)
other - the other version to compare totrue if this version is greater than or equal
to the other version or false otherwisecompareTo(Version other)public boolean lessThan(Version other)
other - the other version to compare totrue if this version is less than the other version
or false otherwisecompareTo(Version other)public boolean lessThanOrEqualTo(Version other)
other - the other version to compare totrue if this version is less than or equal
to the other version or false otherwisecompareTo(Version other)public boolean equals(java.lang.Object other)
Version.compareTo method.equals in class java.lang.Objectother - the other version to compare totrue if this version equals the other version
or false otherwisecompareTo(Version other)public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int compareTo(Version other)
Version.compareWithBuildsTo method or the
Version.BUILD_AWARE_ORDER comparator.compareTo in interface java.lang.Comparable<Version>other - the other version to compare toBUILD_AWARE_ORDER,
compareWithBuildsTo(Version other)public int compareWithBuildsTo(Version other)
Version.BUILD_AWARE_ORDER comparator.other - the other version to compare toComparable.compareTo methodBUILD_AWARE_ORDER