Package org.pkl.core

Class 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.

    • Constructor Summary

      Constructors 
      Constructor Description
      Version​(int major, int minor, int patch, @Nullable java.lang.String preRelease, @Nullable java.lang.String build)
      Constructs a semantic version.
    • 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.
      int compareTo​(Version other)
      Compares this version to the given version according to semantic versioning rules.
      boolean equals​(@Nullable java.lang.Object obj)
      Tells if this version is equal to obj according to semantic versioning rules.
      @Nullable java.lang.String getBuild()
      Returns the build metadata (if any).
      int getMajor()
      Returns the major version.
      int getMinor()
      Returns the minor version.
      int getPatch()
      Returns the patch version.
      @Nullable java.lang.String getPreRelease()
      Returns the pre-release version (if any).
      int hashCode()  
      boolean isNormal()
      Tells if this version has no pre-release version or build metadata.
      boolean isStable()
      Tells if this version has a non-zero major version and no pre-release version.
      static Version parse​(java.lang.String version)
      Parses the given string as a semantic version number.
      static @Nullable Version parseOrNull​(java.lang.String version)
      Parses the given string as a semantic version number.
      Version toNormal()
      Strips any pre-release version and build metadata from this version.
      java.lang.String toString()  
      Version withBuild​(@Nullable java.lang.String build)
      Returns a copy of this version with the given build metadata.
      Version withMajor​(int major)
      Returns a copy of this version with the given major version.
      Version withMinor​(int minor)
      Returns a copy of this version with the given minor version.
      Version withPatch​(int patch)
      Returns a copy of this version with the given patch version.
      Version withPreRelease​(@Nullable java.lang.String preRelease)
      Returns a copy of this version with the given pre-release version.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Version

        public Version​(int major,
                       int minor,
                       int patch,
                       @Nullable java.lang.String preRelease,
                       @Nullable java.lang.String build)
        Constructs a semantic version.
    • Method Detail

      • parse

        public static Version parse​(java.lang.String version)
        Parses the given string as a semantic version number.

        Throws IllegalArgumentException if the given string could not be parsed as a semantic version number or is too large to fit into a Version.

      • parseOrNull

        public static @Nullable Version parseOrNull​(java.lang.String version)
        Parses the given string as a semantic version number.

        Returns null if the given string could not be parsed as a semantic version number or is too large to fit into a Version.

      • 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:
        compareTo in interface java.lang.Comparable<Version>
      • equals

        public boolean equals​(@Nullable java.lang.Object obj)
        Tells if this version is equal to obj according to semantic versioning rules.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object