Record Class SemanticVersion

java.lang.Object
java.lang.Record
com.cleanroommc.versioning.SemanticVersion
Record Components:
major - major component
minor - minor component
patch - patch component
All Implemented Interfaces:
Serializable, Comparable<SemanticVersion>

public record SemanticVersion(long major, long minor, long patch) extends Record implements Comparable<SemanticVersion>, Serializable
A strict numeric semantic version used by release tags.
See Also:
  • Field Details

    • INITIAL

      public static final SemanticVersion INITIAL
      The baseline used before the first tag exists.
  • Constructor Details

    • SemanticVersion

      public SemanticVersion(long major, long minor, long patch)
      Creates an instance of a SemanticVersion record class.
      Parameters:
      major - the value for the major record component
      minor - the value for the minor record component
      patch - the value for the patch record component
  • Method Details

    • parse

      public static SemanticVersion parse(String value)
      Parses a strict numeric version.
      Parameters:
      value - the text to parse
      Returns:
      the parsed version
      Throws:
      IllegalArgumentException - if the text is not <major>.<minor>.<patch>, with an optional v prefix
    • parseTarget

      public static SemanticVersion parseTarget(String value)
      Parses the version a development branch leads to. The patch component may be omitted and has to be zero when present, because a patch is a fix on top of a release rather than something a line is developed towards.
      Parameters:
      value - the text to parse
      Returns:
      the parsed target
      Throws:
      IllegalArgumentException - if the text names no target, or names one carrying a patch
    • isValid

      public static boolean isValid(String value)
      Parameters:
      value - the text to test
      Returns:
      whether the text is a strict numeric version, with or without a v prefix
    • nextPatch

      public SemanticVersion nextPatch()
      Returns:
      the start of the next patch line
    • compareTo

      public int compareTo(SemanticVersion other)
      Specified by:
      compareTo in interface Comparable<SemanticVersion>
    • toString

      public 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 long major()
      Returns the value of the major record component.
      Returns:
      the value of the major record component
    • minor

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

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