Package io.github.chrimle.semver
Record Class SemVer
java.lang.Object
java.lang.Record
io.github.chrimle.semver.SemVer
- Record Components:
major- version. MUST NOT be negative. MAY be0under initial development.minor- version. MUST NOT be negative.patch- version. MUST NOT be negative.
- All Implemented Interfaces:
Comparable<SemVer>
@API(status=STABLE,
since="1.0.1")
public record SemVer(int major, int minor, int patch)
extends Record
implements Comparable<SemVer>
Represents a Release Version Number adhering to Semantic
Versioning.
- Since:
- 1.0.0
- Author:
- Chrimle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@NotNull SemVerCreates a newSemVerwith themajor-version incremented.@NotNull SemVerCreates a newSemVerwith theminor-version incremented.@NotNull SemVerCreates a newSemVerwith thepatch-version incremented.incrementVersion(Change change) Creates a newSemVerwith the corresponding version incremented.intmajor()Returns the value of themajorrecord component.intminor()Returns the value of theminorrecord component.intpatch()Returns the value of thepatchrecord component.@NotNull String@NotNull StringReturns thisSemVeras aStringin the format:v{major}.{minor}.{patch}- where trailing zero versions are omitted.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SemVer
@API(status=STABLE, since="1.2.0") public SemVer(int major, int minor, int patch) Constructs a validSemVerinstance.- Parameters:
major- version.minor- version.patch- version.- Throws:
IllegalArgumentException- ifmajoris less than0.IllegalArgumentException- ifminoris less than0.IllegalArgumentException- ifpatchis less than0.- Since:
- 1.0.0
-
-
Method Details
-
incrementVersion
@API(status=STABLE, since="1.2.0") @Contract("null -> fail") public SemVer incrementVersion(Change change) Creates a newSemVerwith the corresponding version incremented.- Parameters:
change- for determining the newSemVer.- Returns:
- the new
SemVer. - Throws:
IllegalArgumentException- ifchangeisnull.ArithmeticException- if the currentmajor,minororpatchversion is equal to 2147483647 and the providedchangewould increment that version, causing an integer overflow.- Since:
- 1.0.0
-
incrementMajor
@API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementMajor()Creates a newSemVerwith themajor-version incremented.- Returns:
- the new
SemVer. - Throws:
ArithmeticException- if thismajoris equal to 2147483647, which would cause an integer overflow when creating the newSemVer.- Since:
- 1.0.0
-
incrementMinor
@API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementMinor()Creates a newSemVerwith theminor-version incremented.- Returns:
- the new
SemVer. - Throws:
ArithmeticException- if thisminoris equal to 2147483647, which would cause an integer overflow when creating the newSemVer.- Since:
- 1.0.0
-
incrementPatch
@API(status=STABLE, since="1.2.0") @NotNull @Contract(" -> new") public @NotNull SemVer incrementPatch()Creates a newSemVerwith thepatch-version incremented.- Returns:
- the new
SemVer. - Throws:
ArithmeticException- if thispatchis equal to 2147483647, which would cause an integer overflow when creating the newSemVer.- Since:
- 1.0.0
-
toCompleteVersionString
@API(status=STABLE, since="1.2.0") @Contract(pure=true) @NotNull public @NotNull String toCompleteVersionString()- Returns:
- the formatted
String. - Since:
- 1.0.0
-
toShortVersionString
Returns thisSemVeras aStringin the format:v{major}.{minor}.{patch}- where trailing zero versions are omitted.Examples:
1.0.0returns"v1"1.2.0returns"v1.2"1.2.3returns"v1.2.3"
- Returns:
- the formatted
String. - Since:
- 1.0.0
-
compareTo
- Specified by:
compareToin interfaceComparable<SemVer>- Throws:
NullPointerException- ifotherisnull.- Since:
- 1.1.0
-
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 with '=='. -
major
public int major()Returns the value of themajorrecord component.- Returns:
- the value of the
majorrecord component
-
minor
public int minor()Returns the value of theminorrecord component.- Returns:
- the value of the
minorrecord component
-
patch
public int patch()Returns the value of thepatchrecord component.- Returns:
- the value of the
patchrecord component
-