public class Version extends Object implements 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 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(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. |
String |
getBuildMetadata()
Returns the string representation of the build metadata.
|
int |
getMajorVersion()
Returns the major version number.
|
int |
getMinorVersion()
Returns the minor version number.
|
String |
getNormalVersion()
Returns the string representation of the normal version.
|
int |
getPatchVersion()
Returns the patch version number.
|
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(String preRelease)
Increments the major version and appends the pre-release version.
|
Version |
incrementMinorVersion()
Increments the minor version.
|
Version |
incrementMinorVersion(String preRelease)
Increments the minor version and appends the pre-release version.
|
Version |
incrementPatchVersion()
Increments the patch version.
|
Version |
incrementPatchVersion(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(String expr)
Checks if this version satisfies the specified SemVer Expression.
|
Version |
setBuildMetadata(String build)
Sets the build metadata.
|
Version |
setPreReleaseVersion(String preRelease)
Sets the pre-release version.
|
String |
toString() |
static Version |
valueOf(String version)
Creates a new instance of
Version as a
result of parsing the specified version string. |
public static final Comparator<Version> BUILD_AWARE_ORDER
public static Version valueOf(String version)
Version
as a
result of parsing the specified version string.version
- the version string to parseVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public static Version forIntegers(int major)
Version
for the specified version numbers.major
- the major version numberVersion
classIllegalArgumentException
- 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
classIllegalArgumentException
- 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
classIllegalArgumentException
- if a negative integer is passedpublic boolean satisfies(String expr)
expr
- the SemVer Expressiontrue
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 Version incrementMajorVersion()
Version
classpublic Version incrementMajorVersion(String preRelease)
preRelease
- the pre-release version to appendVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public Version incrementMinorVersion()
Version
classpublic Version incrementMinorVersion(String preRelease)
preRelease
- the pre-release version to appendVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public Version incrementPatchVersion()
Version
classpublic Version incrementPatchVersion(String preRelease)
preRelease
- the pre-release version to appendVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public Version incrementPreReleaseVersion()
Version
classpublic Version incrementBuildMetadata()
Version
classpublic Version setPreReleaseVersion(String preRelease)
preRelease
- the pre-release version to setVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public Version setBuildMetadata(String build)
build
- the build metadata to setVersion
classIllegalArgumentException
- if the input string is NULL
or emptyParseException
- when invalid version string is providedUnexpectedCharacterException
- is a special case of ParseException
public int getMajorVersion()
public int getMinorVersion()
public int getPatchVersion()
public String getNormalVersion()
public String getPreReleaseVersion()
public 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(Object other)
Version.compareTo
method.equals
in class Object
other
- the other version to compare totrue
if this version equals the other version
or false
otherwisecompareTo(Version other)
public int compareTo(Version other)
Version.compareWithBuildsTo
method or the
Version.BUILD_AWARE_ORDER
comparator.compareTo
in interface 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
Copyright © 2015. All rights reserved.