Class SemanticVersion
java.lang.Object
io.github.bakedlibs.dough.versions.SemanticVersion
- All Implemented Interfaces:
Version,Comparable<Version>
- Direct Known Subclasses:
MinecraftVersion
A
SemanticVersion follows the semantic version convention.
The version itself consists of three components, a major version number,
a minor version number and a patch version number.
The components are read and compared in that exact order. If the patch version number is zero, it may be omitted from the version string.
- Author:
- TheBusyBiscuit
-
Constructor Summary
ConstructorsConstructorDescriptionSemanticVersion(int major, int minor) This creates a newSemanticVersioninstance with the given components.SemanticVersion(int major, int minor, int patch) This creates a newSemanticVersioninstance with the given components. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanequalsIgnorePatch(int majorVersion, int minorVersion) This method returns whether thisSemanticVersionequals the provided version numbers (ignoring the patch version of thisSemanticVersion).booleanequalsIgnorePatch(SemanticVersion version) This method returns whether thisSemanticVersionequals the provided version in all aspects except their patch number.This method returns thisVersionas a human-readable format.final intThis returns the "major" version component of thisSemanticVersion.final intThis returns the "minor" version component of thisSemanticVersion.final intThis returns the "patch" version component of thisSemanticVersion.inthashCode()booleanisAtLeast(int major, int minor) booleanisAtLeast(int major, int minor, int patch) booleanbooleanisNewerThan(Version version) booleanisOlderThan(Version version) final booleanisPatch()This method returns whether this is a patch version.booleanstatic SemanticVersionThis method attempts to parse the givenStringas aSemanticVersion.toString()
-
Constructor Details
-
SemanticVersion
public SemanticVersion(int major, int minor, int patch) This creates a newSemanticVersioninstance with the given components.- Parameters:
major- The major versionminor- The minor versionpatch- The patch version
-
SemanticVersion
public SemanticVersion(int major, int minor) This creates a newSemanticVersioninstance with the given components.The patch version will be automatically assumed to be zero.
- Parameters:
major- The major versionminor- The minor version
-
-
Method Details
-
getMajorVersion
public final int getMajorVersion()This returns the "major" version component of thisSemanticVersion.- Returns:
- The major version
-
getMinorVersion
public final int getMinorVersion()This returns the "minor" version component of thisSemanticVersion.- Returns:
- The minor version
-
getPatchVersion
public final int getPatchVersion()This returns the "patch" version component of thisSemanticVersion.- Returns:
- The patch version
-
isPatch
public final boolean isPatch()This method returns whether this is a patch version. ASemanticVersionis considered a "patch" when their last component (getPatchVersion()) is greater than zero.- Returns:
- Whether this is a patch version
-
isAtLeast
public boolean isAtLeast(int major, int minor, int patch) -
isAtLeast
public boolean isAtLeast(int major, int minor) -
isSimilar
This returns whether thisVersionis "similar" to the givenVersion. TwoVersions are considered "similar" when they can be compared to each other without causing anIncomparableVersionsException. -
isNewerThan
This method returns whether thisVersionis newer than the providedVersion. This also implies that the providedVersionis older than thisVersion, seeVersion.isOlderThan(Version).This method may throw an
IncomparableVersionsExceptionif the two versions cannot be compared with each other.- Specified by:
isNewerThanin interfaceVersion- Parameters:
version- TheVersionto compare this to- Returns:
- Whether this
Versionis newer than the provided one.
-
isEqualTo
This method returns whether thisVersionis equal to the givenVersion.This method may throw an
IncomparableVersionsExceptionif the two versions cannot be compared with each other. -
isOlderThan
This method returns whether thisVersionis older than the providedVersion. This also implies that the providedVersionis newer than thisVersion, seeVersion.isNewerThan(Version).This method may throw an
IncomparableVersionsExceptionif the two versions cannot be compared with each other.- Specified by:
isOlderThanin interfaceVersion- Parameters:
version- TheVersionto compare this to- Returns:
- Whether this
Versionis older than the provided one.
-
getAsString
This method returns thisVersionas a human-readable format. Example:1.4.2.- Specified by:
getAsStringin interfaceVersion- Returns:
- A human-readable
Stringrepresentation of thisVersion
-
hashCode
public int hashCode() -
equals
-
toString
-
equalsIgnorePatch
This method returns whether thisSemanticVersionequals the provided version in all aspects except their patch number.This will only compare the major and minor versions.
- Parameters:
version- TheSemanticVersionto compare this to- Returns:
- Whether the two versions are equal (ignoring their patch version)
-
equalsIgnorePatch
public boolean equalsIgnorePatch(int majorVersion, int minorVersion) This method returns whether thisSemanticVersionequals the provided version numbers (ignoring the patch version of thisSemanticVersion).- Parameters:
majorVersion- The major versionminorVersion- The minor version- Returns:
- Whether the two versions are equal (ignoring their patch version)
-
parse
This method attempts to parse the givenStringas aSemanticVersion. If theStringcould not be parsed effectively, anIllegalArgumentExceptionwill be thrown.Note that the String should follow the
SemanticVersionconvention, such as "1.0.2", "1.2.10", "1.3.0" or "1.1" to name a few examples.- Parameters:
version- The version string to parse- Returns:
- The resulting
SemanticVersion
-