Record Class SemVer

java.lang.Object
java.lang.Record
io.github.chrimle.classforge.semver.SemVer
Record Components:
major - version.
minor - version.
patch - version.

public record SemVer(int major, int minor, int patch) extends Record
Represents a Semantic Version (SemVer).
Since:
0.3.0
Author:
Chrimle
  • Constructor Details

  • Method Details

    • incrementVersion

      @Contract("null -> fail") public SemVer incrementVersion(SemVer.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.
      Since:
      0.3.0
    • incrementMajor

      @NotNull @Contract(" -> new") public SemVer incrementMajor()
      Creates a new SemVer with the major-version incremented.
      Returns:
      the new SemVer.
      Since:
      0.3.0
    • incrementMinor

      @NotNull @Contract(" -> new") public SemVer incrementMinor()
      Creates a new SemVer with the minor-version incremented.
      Returns:
      the new SemVer.
      Since:
      0.3.0
    • incrementPatch

      @NotNull @Contract(" -> new") public SemVer incrementPatch()
      Creates a new SemVer with the patch-version incremented.
      Returns:
      the new SemVer.
      Since:
      0.3.0
    • toString

      @NotNull @Contract(pure=true) public String toString()
      Returns this SemVer as a String in the format: v{major}.{minor}.{patch}.
      Specified by:
      toString in class Record
      Returns:
      the formatted String.
      Since:
      0.3.0
    • toShortVersionString

      @NotNull public String toShortVersionString()
      Returns this SemVer as a String in the format: v{major}.{minor}.{patch} - where trailing zero sub-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:
      0.4.0
    • 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