Record Class Version

java.lang.Object
java.lang.Record
dev.architectury.loom.util.Version
All Implemented Interfaces:
Comparable<Version>

public record Version(int major, int minor, int micro, int patch, @Nullable String qualifier) extends Record implements Comparable<Version>
A simple version class that can be used to compare versions. This class allows for versions that are not strictly following the semver specification, but are still allowed in the context of gradle versioning.

This class is intentionally very flexible and does not enforce any specific versioning scheme, and should be very similar to the versioning used by gradle itself.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Version
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
     
    int
    compareTo(@NonNull Version other)
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the major record component.
    int
    Returns the value of the micro record component.
    int
    Returns the value of the minor record component.
    static Version
    parse(String version)
     
    static Version
    parse(String version, boolean withPatch)
     
    int
    Returns the value of the patch record component.
    @Nullable String
    Returns the value of the qualifier record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • UNKNOWN

      public static final Version UNKNOWN
  • Constructor Details

    • Version

      public Version(int major, int minor, int micro, int patch, @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
      micro - the value for the micro record component
      patch - the value for the patch record component
      qualifier - the value for the qualifier record component
  • Method Details

    • parse

      public static Version parse(String version)
    • parse

      public static Version parse(String version, boolean withPatch)
    • asBaseVersion

      public Version asBaseVersion()
    • compareTo

      public int compareTo(@NonNull Version other)
      Specified by:
      compareTo in interface Comparable<Version>
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components 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
    • micro

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

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

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