Record Class VersibleVersion

java.lang.Object
java.lang.Record
dev.gigaherz.versible.VersibleVersion
All Implemented Interfaces:
Comparable<VersibleVersion>

public record VersibleVersion(@NotNull List<VersibleComponent> components) extends Record implements Comparable<VersibleVersion>
Represents a version string as a collection of version components.
  • Constructor Details

    • VersibleVersion

      @Internal public VersibleVersion(@NotNull @NotNull List<VersibleComponent> components)
      Constructs the version with the given components. To parse a version from string, VersibleParser.parseVersion(String) should be used instead. To construct an object, of(Object...) should be used instead.
      Parameters:
      components - The list of components. Cannot be empty. In order to maintain immutability, this must be an unmodifiable or immutable list.
  • Method Details

    • of

      public static VersibleVersion of(Object... components)
      Returns a VersibleVersion with the given sequence of component values, by parsing each component value into the corresponding VersibleComponent.
      Parameters:
      components - A variadic array of component objects. Numbers (integers), Strings, and Characters are allowed.
      Returns:
      The version containing the given sequence of components.
      Throws:
      IllegalArgumentException - If an object in the array cannot be converted into a component.
    • size

      public int size()
      Returns the number of components in this version.
      Returns:
      The number of components in this version.
    • get

      public VersibleComponent get(int index)
      Returns the component at the specified position in the component list.
      Parameters:
      index - The index of the element to return.
      Returns:
      The component at the specified position in the component list.
      Throws:
      IndexOutOfBoundsException - If the index is out of range (index < 0 || index >= size()).
    • stream

      public Stream<VersibleComponent> stream()
      Returns a sequential Stream with the component collection as its source.
      Returns:
      a sequential Stream over the elements in the component collection
    • compareTo

      public int compareTo(VersibleVersion o)
      Specified by:
      compareTo in interface Comparable<VersibleVersion>
    • append

      public VersibleVersion append(VersibleVersion other)
      Returns a new VersibleVersion with the components of another version concatenated after the components of this version.
      Parameters:
      other - The version to append components from.
      Returns:
      The version with the concatenated components.
    • bump

      public VersibleVersion bump(int index)
      Returns a new VersibleVersion with the given numeric component incremented by one.
      Parameters:
      index - The index of the component to increment.
      Returns:
      The version string corresponding to the version with the incremented component.
      Throws:
      IllegalArgumentException - If the component at the given index is not a numeric component.
    • 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 Objects::equals(Object,Object).
      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.
    • components

      @NotNull public @NotNull List<VersibleComponent> components()
      Returns the value of the components record component.
      Returns:
      the value of the components record component