Package org.pkl.core

Class Version

java.lang.Object
org.pkl.core.Version
All Implemented Interfaces:
Comparable<Version>

public final class Version extends Object implements Comparable<Version>
A semantic version.

This class guarantees that valid semantic version numbers are handled correctly, but does not guarantee that invalid semantic version numbers are rejected.

  • Constructor Details

  • Method Details

    • parse

      public static Version parse(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

      @Nullable public static @Nullable Version parseOrNull(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 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

      @Nullable public @Nullable String getPreRelease()
      Returns the pre-release version (if any).
    • withPreRelease

      public Version withPreRelease(@Nullable @Nullable String preRelease)
      Returns a copy of this version with the given pre-release version.
    • getBuild

      @Nullable public @Nullable String getBuild()
      Returns the build metadata (if any).
    • withBuild

      public Version withBuild(@Nullable @Nullable 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 Comparable<Version>
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object