Class SemanticVersion
- java.lang.Object
-
- io.getunleash.strategy.constraints.SemanticVersion
-
- All Implemented Interfaces:
Comparable<SemanticVersion>
public class SemanticVersion extends Object implements 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 Modifier and Type Class Description static classSemanticVersion.InvalidVersionException
-
Constructor Summary
Constructors Constructor Description SemanticVersion(int major, int minor, int patch, String preRelease, String build)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcomparePrecedence(SemanticVersion other)Compares this object with another SemanticVersion according to Semver 2.0.0 precedence rules.intcompareTo(SemanticVersion other)StringgetBuild()intgetMajor()intgetMinor()intgetPatch()StringgetPreRelease()String[]getPreReleaseComponents()static SemanticVersionparse(String input)Attempts to parse a string as a semantic version according to the Semver 2.0.0 specification.static SemanticVersionparse(String input, boolean allowMissingMinorAndPatch)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.
-
-
-
Method Detail
-
getMajor
public int getMajor()
-
getMinor
public int getMinor()
-
getPatch
public int getPatch()
-
getPreRelease
public String getPreRelease()
-
getPreReleaseComponents
public String[] getPreReleaseComponents()
-
getBuild
public String getBuild()
-
parse
public static SemanticVersion parse(String input) throws SemanticVersion.InvalidVersionException
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
public int compareTo(SemanticVersion other)
- Specified by:
compareToin interfaceComparable<SemanticVersion>
-
comparePrecedence
public int comparePrecedence(SemanticVersion other)
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
-
-