Record Class SemVer

java.lang.Object
java.lang.Record
io.github.chrimle.semver.SemVer
Record Components:
major - version. MUST NOT be negative. MAY be 0 under initial development.
minor - version. MUST NOT be negative.
patch - version. MUST NOT be negative.
All Implemented Interfaces:
Comparable<SemVer>

@API(status=STABLE, since="1.0.1") public record SemVer(int major, int minor, int patch) extends Record implements Comparable<SemVer>
Represents a Release Version Number adhering to Semantic Versioning.
Since:
1.0.0
Author:
Chrimle
  • Constructor Details

  • Method Details

    • incrementVersion

      @API(status=STABLE, since="1.2.0") @Contract("null -> fail") public SemVer incrementVersion(Change change)
      Creates a new SemVer with the corresponding version incremented.
      Parameters:
      change - for determining the new SemVer.
      Returns:
      the new SemVer.
      Throws:
      IllegalArgumentException - if change is null.
      ArithmeticException - if the current major, minor or patch version is equal to 2147483647 and the provided change would increment that version, causing an integer overflow.
      Since:
      1.0.0
    • incrementMajor

      @API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementMajor()
      Creates a new SemVer with the major-version incremented.
      Returns:
      the new SemVer.
      Throws:
      ArithmeticException - if this major is equal to 2147483647, which would cause an integer overflow when creating the new SemVer.
      Since:
      1.0.0
    • incrementMinor

      @API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementMinor()
      Creates a new SemVer with the minor-version incremented.
      Returns:
      the new SemVer.
      Throws:
      ArithmeticException - if this minor is equal to 2147483647, which would cause an integer overflow when creating the new SemVer.
      Since:
      1.0.0
    • incrementPatch

      @API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementPatch()
      Creates a new SemVer with the patch-version incremented.
      Returns:
      the new SemVer.
      Throws:
      ArithmeticException - if this patch is equal to 2147483647, which would cause an integer overflow when creating the new SemVer.
      Since:
      1.0.0
    • toCompleteVersionString

      @API(status=STABLE, since="1.2.0") @Contract(pure=true) @NotNull public @NotNull String toCompleteVersionString()
      Returns this SemVer as a String in the format: v{major}.{minor}.{patch}.
      Returns:
      the formatted String.
      Since:
      1.0.0
    • toShortVersionString

      @API(status=STABLE, since="1.2.0") @NotNull public @NotNull String toShortVersionString()
      Returns this SemVer as a String in the format: v{major}.{minor}.{patch} - where trailing zero versions are omitted.

      Examples:

      • 1.0.0 returns "v1"
      • 1.2.0 returns "v1.2"
      • 1.2.3 returns "v1.2.3"
      Returns:
      the formatted String.
      Since:
      1.0.0
    • compareTo

      @API(status=STABLE, since="1.2.0") public int compareTo(SemVer other)
      Specified by:
      compareTo in interface Comparable<SemVer>
      Throws:
      NullPointerException - if other is null.
      Since:
      1.1.0
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • major

      public int major()
      Returns the value of the major record component.
      Returns:
      the value of the major record component
    • minor

      public int minor()
      Returns the value of the minor record component.
      Returns:
      the value of the minor record component
    • patch

      public int patch()
      Returns the value of the patch record component.
      Returns:
      the value of the patch record component