Package org.pkl.core
Class Version
- java.lang.Object
-
- org.pkl.core.Version
-
- All Implemented Interfaces:
java.lang.Comparable<Version>
public final class Version extends java.lang.Object implements java.lang.Comparable<Version>
A semantic version (https://semver.org/spec/v2.0.0.html).This class guarantees that valid semantic version numbers are handled correctly, but does not guarantee that invalid semantic version numbers are rejected.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.Comparator<Version>comparator()Returns a comparator for semantic versions.intcompareTo(Version other)Compares this version to the given version according to semantic versioning rules.booleanequals(@Nullable java.lang.Object obj)Tells if this version is equal toobjaccording to semantic versioning rules.@Nullable java.lang.StringgetBuild()Returns the build metadata (if any).intgetMajor()Returns the major version.intgetMinor()Returns the minor version.intgetPatch()Returns the patch version.@Nullable java.lang.StringgetPreRelease()Returns the pre-release version (if any).inthashCode()booleanisNormal()Tells if this version has no pre-release version or build metadata.booleanisStable()Tells if this version has a non-zero major version and no pre-release version.static Versionparse(java.lang.String version)Parses the given string as a semantic version number.static @Nullable VersionparseOrNull(java.lang.String version)Parses the given string as a semantic version number.VersiontoNormal()Strips any pre-release version and build metadata from this version.java.lang.StringtoString()VersionwithBuild(@Nullable java.lang.String build)Returns a copy of this version with the given build metadata.VersionwithMajor(int major)Returns a copy of this version with the given major version.VersionwithMinor(int minor)Returns a copy of this version with the given minor version.VersionwithPatch(int patch)Returns a copy of this version with the given patch version.VersionwithPreRelease(@Nullable java.lang.String preRelease)Returns a copy of this version with the given pre-release version.
-
-
-
Method Detail
-
parse
public static Version parse(java.lang.String version)
Parses the given string as a semantic version number.Throws
IllegalArgumentExceptionif the given string could not be parsed as a semantic version number or is too large to fit into aVersion.
-
parseOrNull
public static @Nullable Version parseOrNull(java.lang.String version)
Parses the given string as a semantic version number.Returns
nullif the given string could not be parsed as a semantic version number or is too large to fit into aVersion.
-
comparator
public static java.util.Comparator<Version> comparator()
Returns a comparator for semantic versions.
-
getMajor
public int getMajor()
Returns the major version.
-
withMajor
public Version withMajor(int major)
Returns a copy of this version with the given major version.
-
getMinor
public int getMinor()
Returns the minor version.
-
withMinor
public Version withMinor(int minor)
Returns a copy of this version with the given minor version.
-
getPatch
public int getPatch()
Returns the patch version.
-
withPatch
public Version withPatch(int patch)
Returns a copy of this version with the given patch version.
-
getPreRelease
public @Nullable java.lang.String getPreRelease()
Returns the pre-release version (if any).
-
withPreRelease
public Version withPreRelease(@Nullable java.lang.String preRelease)
Returns a copy of this version with the given pre-release version.
-
getBuild
public @Nullable java.lang.String getBuild()
Returns the build metadata (if any).
-
withBuild
public Version withBuild(@Nullable java.lang.String build)
Returns a copy of this version with the given build metadata.
-
isNormal
public boolean isNormal()
Tells if this version has no pre-release version or build metadata.
-
isStable
public boolean isStable()
Tells if this version has a non-zero major version and no pre-release version.
-
toNormal
public Version toNormal()
Strips any pre-release version and build metadata from this version.
-
compareTo
public int compareTo(Version other)
Compares this version to the given version according to semantic versioning rules.- Specified by:
compareToin interfacejava.lang.Comparable<Version>
-
equals
public boolean equals(@Nullable java.lang.Object obj)
Tells if this version is equal toobjaccording to semantic versioning rules.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-