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).
  • Constructor Details

    • SemanticVersion

      public SemanticVersion(int major, int minor, int patch, String preRelease, String build)
  • Method Details

    • 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

      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 string
      allowMissingMinorAndPatch - 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:
      compareTo in interface Comparable<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