Skip to content

Package io.github.qishr.cascara.common.semver

Class SemVer

java.lang.Object
        io.github.qishr.cascara.common.semver.SemVer

All Implemented Interfaces:
    Comparable<SemVer>


public class SemVer

Semver is a tool that provides useful methods to manipulate versions that follow the "semantic versioning" specification (see http://semver.org)

Constructor Summary

Constructor Description
SemVer(String value)
SemVer(String value, SemVerType type)

Method Summary

Modifier and Type Method Description
public boolean satisfies(Requirement requirement) Check if the version satisfies a requirement
public boolean satisfies(String requirement) Check if the version satisfies a requirement
public boolean isGreaterThan(String version)
public boolean isGreaterThan(SemVer version) Checks if the version is greater than another version
public boolean isGreaterThanOrEqualTo(String version)
public boolean isGreaterThanOrEqualTo(SemVer version) Checks if the version is greater than or equal to another version
public boolean isLowerThan(String version)
public boolean isLowerThan(SemVer version) Checks if the version is lower than another version
public boolean isLowerThanOrEqualTo(String version)
public boolean isLowerThanOrEqualTo(SemVer version) Checks if the version is lower than or equal to another version
public boolean isEquivalentTo(String version)
public boolean isEquivalentTo(SemVer version) Checks if the version equals another version, without taking the build into account.
public boolean isEqualTo(String version)
public boolean isEqualTo(SemVer version) Checks if the version equals another version
public boolean isStable() Determines if the current version is stable or not.
public VersionDiff diff(String version)
public VersionDiff diff(SemVer version) Returns the greatest difference between 2 versions.
public SemVer toStrict()
public SemVer withIncMajor()
public SemVer withIncMajor(int increment)
public SemVer withIncMinor()
public SemVer withIncMinor(int increment)
public SemVer withIncPatch()
public SemVer withIncPatch(int increment)
public SemVer withClearedSuffix()
public SemVer withClearedBuild()
public SemVer withClearedSuffixAndBuild()
public SemVer withSuffix(String suffix)
public SemVer withBuild(String build)
public SemVer nextMajor()
public SemVer nextMinor()
public SemVer nextPatch()
public boolean equals(Object o)
public int hashCode()
public int compareTo(SemVer version)
public String toString()
public String getOriginalValue() Get the original value as a string
public String getValue() Returns the version as a String
public Integer getMajor() Returns the major part of the version.
public Integer getMinor() Returns the minor part of the version.
public Integer getPatch() Returns the patch part of the version.
public String[] getSuffixTokens() Returns the suffix of the version.
public String getBuild() Returns the build of the version.
public SemVerType getType()

Method Details

satisfies

public boolean satisfies(Requirement requirement)

Check if the version satisfies a requirement

Parameters:

requirement - the requirement

Returns:

true if the version satisfies the requirement


satisfies

public boolean satisfies(String requirement)

Check if the version satisfies a requirement

Parameters:

requirement - the requirement

Returns:

true if the version satisfies the requirement


isGreaterThan

public boolean isGreaterThan(String version)

Parameters:

version - the version to compare

Returns:

true if the current version is greater than the provided version

See Also:

isGreaterThan


isGreaterThan

public boolean isGreaterThan(SemVer version)

Checks if the version is greater than another version

Parameters:

version - the version to compare

Returns:

true if the current version is greater than the provided version


isGreaterThanOrEqualTo

public boolean isGreaterThanOrEqualTo(String version)

Parameters:

version - the version to compare

Returns:

true if the current version is greater than or equal to the provided version

See Also:

isGreaterThanOrEqualTo


isGreaterThanOrEqualTo

public boolean isGreaterThanOrEqualTo(SemVer version)

Checks if the version is greater than or equal to another version

Parameters:

version - the version to compare

Returns:

true if the current version is greater than or equal to the provided version


isLowerThan

public boolean isLowerThan(String version)

Parameters:

version - the version to compare

Returns:

true if the current version is lower than the provided version

See Also:

isLowerThan


isLowerThan

public boolean isLowerThan(SemVer version)

Checks if the version is lower than another version

Parameters:

version - the version to compare

Returns:

true if the current version is lower than the provided version


isLowerThanOrEqualTo

public boolean isLowerThanOrEqualTo(String version)

Parameters:

version - the version to compare

Returns:

true if the current version is lower than or equal to the provided version

See Also:

isLowerThanOrEqualTo


isLowerThanOrEqualTo

public boolean isLowerThanOrEqualTo(SemVer version)

Checks if the version is lower than or equal to another version

Parameters:

version - the version to compare

Returns:

true if the current version is lower than or equal to the provided version


isEquivalentTo

public boolean isEquivalentTo(String version)

Parameters:

version - the version to compare

Returns:

true if the current version equals the provided version (build excluded)

See Also:

isEquivalentTo


isEquivalentTo

public boolean isEquivalentTo(SemVer version)

Checks if the version equals another version, without taking the build into account.

Parameters:

version - the version to compare

Returns:

true if the current version equals the provided version (build excluded)


isEqualTo

public boolean isEqualTo(String version)

Parameters:

version - the version to compare

Returns:

true if the current version equals the provided version

See Also:

isEqualTo


isEqualTo

public boolean isEqualTo(SemVer version)

Checks if the version equals another version

Parameters:

version - the version to compare

Returns:

true if the current version equals the provided version


isStable

public boolean isStable()

Determines if the current version is stable or not.Stable version have a major version number strictly positive and no suffix tokens.

Returns:

true if the current version is stable


diff

public VersionDiff diff(String version)

Parameters:

version - the version to compare

Returns:

the greatest difference

See Also:

diff


diff

public VersionDiff diff(SemVer version)

Returns the greatest difference between 2 versions.For example, if the current version is "1.2.3" and compared version is "1.3.0", the biggest difference is the 'MINOR' number.

Parameters:

version - the version to compare

Returns:

the greatest difference


toStrict

public SemVer toStrict()


withIncMajor

public SemVer withIncMajor()


withIncMajor

public SemVer withIncMajor(int increment)


withIncMinor

public SemVer withIncMinor()


withIncMinor

public SemVer withIncMinor(int increment)


withIncPatch

public SemVer withIncPatch()


withIncPatch

public SemVer withIncPatch(int increment)


withClearedSuffix

public SemVer withClearedSuffix()


withClearedBuild

public SemVer withClearedBuild()


withClearedSuffixAndBuild

public SemVer withClearedSuffixAndBuild()


withSuffix

public SemVer withSuffix(String suffix)


withBuild

public SemVer withBuild(String build)


nextMajor

public SemVer nextMajor()


nextMinor

public SemVer nextMinor()


nextPatch

public SemVer nextPatch()


equals

public boolean equals(Object o)


hashCode

public int hashCode()


compareTo

public int compareTo(SemVer version)


toString

public String toString()


getOriginalValue

public String getOriginalValue()

Get the original value as a string

Returns:

the original string passed in the constructor


getValue

public String getValue()

Returns the version as a String

Returns:

the version as a String


getMajor

public Integer getMajor()

Returns the major part of the version.Example: for "1.2.3" = 1

Returns:

the major part of the version


getMinor

public Integer getMinor()

Returns the minor part of the version.Example: for "1.2.3" = 2

Returns:

the minor part of the version


getPatch

public Integer getPatch()

Returns the patch part of the version.Example: for "1.2.3" = 3

Returns:

the patch part of the version


getSuffixTokens

public String[] getSuffixTokens()

Returns the suffix of the version.Example: for "1.2.3-beta.4+sha98450956" = {"beta", "4"}

Returns:

the suffix of the version


getBuild

public String getBuild()

Returns the build of the version.Example: for "1.2.3-beta.4+sha98450956" = "sha98450956"

Returns:

the build of the version


getType

public SemVerType getType()