Package dev.gigaherz.versible
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 Summary
ConstructorsConstructorDescriptionVersibleVersion(@NotNull List<VersibleComponent> components) Constructs the version with the given components. -
Method Summary
Modifier and TypeMethodDescriptionappend(VersibleVersion other) Returns a newVersibleVersionwith the components of another version concatenated after the components of this version.bump(int index) Returns a newVersibleVersionwith the given numeric component incremented by one.int@NotNull List<VersibleComponent>Returns the value of thecomponentsrecord component.final booleanIndicates whether some other object is "equal to" this one.get(int index) Returns the component at the specified position in the component list.final inthashCode()Returns a hash code value for this object.static VersibleVersionReturns aVersibleVersionwith the given sequence of component values, by parsing each component value into the correspondingVersibleComponent.intsize()Returns the number of components in this version.stream()Returns a sequentialStreamwith the component collection as its source.toString()Returns a string representation of this record class.
-
Constructor Details
-
VersibleVersion
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
Returns aVersibleVersionwith the given sequence of component values, by parsing each component value into the correspondingVersibleComponent.- 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
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
Returns a sequentialStreamwith the component collection as its source.- Returns:
- a sequential
Streamover the elements in the component collection
-
compareTo
- Specified by:
compareToin interfaceComparable<VersibleVersion>
-
append
Returns a newVersibleVersionwith 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
Returns a newVersibleVersionwith 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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
components
Returns the value of thecomponentsrecord component.- Returns:
- the value of the
componentsrecord component
-