Record Class Version

java.lang.Object
java.lang.Record
fr.robie.machineengine.api.version.Version
All Implemented Interfaces:
Comparable<Version>

public record Version(int major, int minor, int patch, @Nullable String qualifier) extends Record implements Comparable<Version>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Version(int major, int minor, int patch, @Nullable String qualifier)
    Creates an instance of a Version record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Version
    Returns this version without its qualifier.
    int
    compareTo(@NotNull Version other)
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    isAfter(@NotNull Version other)
    Returns whether this version is strictly greater than other.
    boolean
    isAtLeast(@NotNull Version other)
    Returns whether this version is greater than or equal to other.
    boolean
    isAtMost(@NotNull Version other)
    Returns whether this version is less than or equal to other.
    boolean
    isBefore(@NotNull Version other)
    Returns whether this version is strictly less than other.
    boolean
    Returns whether this version has a qualifier.
    boolean
    Returns whether this version is a stable release.
    int
    Returns the value of the major record component.
    int
    Returns the value of the minor record component.
    static @NotNull Version
    of(int major, int minor, int patch)
    Creates a version without a qualifier.
    static @NotNull Version
    of(int major, int minor, int patch, @Nullable String qualifier)
    Creates a version with a qualifier.
    static @NotNull Version
    parse(@NotNull String text)
    Parses a version string.
    int
    Returns the value of the patch record component.
    @Nullable String
    Returns the value of the qualifier record component.
    @NotNull String
    Returns the version in canonical form.

    Methods inherited from class Object

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

    • Version

      public Version(int major, int minor, int patch, @Nullable @Nullable String qualifier)
      Creates an instance of a Version 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
      qualifier - the value for the qualifier record component
  • Method Details

    • of

      @NotNull public static @NotNull Version of(int major, int minor, int patch)
      Creates a version without a qualifier.
    • of

      @NotNull public static @NotNull Version of(int major, int minor, int patch, @Nullable @Nullable String qualifier)
      Creates a version with a qualifier.
    • parse

      @NotNull public static @NotNull Version parse(@NotNull @NotNull String text)
      Parses a version string.
      Parameters:
      text - version text
      Returns:
      parsed version
      Throws:
      IllegalArgumentException - if the text is not a valid version
    • base

      @NotNull public @NotNull Version base()
      Returns this version without its qualifier.
    • isAtLeast

      public boolean isAtLeast(@NotNull @NotNull Version other)
      Returns whether this version is greater than or equal to other.
    • isAtMost

      public boolean isAtMost(@NotNull @NotNull Version other)
      Returns whether this version is less than or equal to other.
    • isAfter

      public boolean isAfter(@NotNull @NotNull Version other)
      Returns whether this version is strictly greater than other.
    • isBefore

      public boolean isBefore(@NotNull @NotNull Version other)
      Returns whether this version is strictly less than other.
    • isQualified

      public boolean isQualified()
      Returns whether this version has a qualifier.
    • isStable

      public boolean isStable()
      Returns whether this version is a stable release.
    • compareTo

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

      @NotNull public @NotNull String toString()
      Returns the version in canonical form.

      Missing minor and patch components are normalized:

      Specified by:
      toString in class Record
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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
    • qualifier

      @Nullable public @Nullable String qualifier()
      Returns the value of the qualifier record component.
      Returns:
      the value of the qualifier record component