Class SemanticVersion
java.lang.Object
io.getunleash.strategy.constraints.SemanticVersion
- All Implemented Interfaces:
Comparable<SemanticVersion>
Simple implementation of semantic version parsing and comparison according to the Semantic
Versions 2.0.0 standard (http://semver.org).
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionSemanticVersion(int major, int minor, int patch, String preRelease, String build) -
Method Summary
Modifier and TypeMethodDescriptionintcomparePrecedence(SemanticVersion other) Compares this object with another SemanticVersion according to Semver 2.0.0 precedence rules.intcompareTo(SemanticVersion other) getBuild()intgetMajor()intgetMinor()intgetPatch()String[]static SemanticVersionAttempts to parse a string as a semantic version according to the Semver 2.0.0 specification.static SemanticVersionAttempts to parse a string as a semantic version according to the Semver 2.0.0 specification, except that the minor and patch versions may optionally be omitted.
-
Constructor Details
-
SemanticVersion
-
-
Method Details
-
getMajor
public int getMajor() -
getMinor
public int getMinor() -
getPatch
public int getPatch() -
getPreRelease
-
getPreReleaseComponents
-
getBuild
-
parse
Attempts to parse a string as a semantic version according to the Semver 2.0.0 specification.- Parameters:
input- the input string- Returns:
- a SemanticVersion instance
- Throws:
SemanticVersion.InvalidVersionException- if the version could not be parsed
-
parse
public static SemanticVersion parse(String input, boolean allowMissingMinorAndPatch) throws SemanticVersion.InvalidVersionException Attempts to parse a string as a semantic version according to the Semver 2.0.0 specification, except that the minor and patch versions may optionally be omitted.- Parameters:
input- the input stringallowMissingMinorAndPatch- true if the parser should tolerate the absence of a minor and/or patch version; if absent, they will be treated as zero- Returns:
- a SemanticVersion instance
- Throws:
SemanticVersion.InvalidVersionException- if the version could not be parsed
-
compareTo
- Specified by:
compareToin interfaceComparable<SemanticVersion>
-
comparePrecedence
Compares this object with another SemanticVersion according to Semver 2.0.0 precedence rules.- Parameters:
other- another SemanticVersion- Returns:
- 0 if equal, -1 if the current object has lower precedence, or 1 if the current object has higher precedence
-