Class SemverVersion

java.lang.Object
i5.las2peer.api.SemverVersion
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
LibraryVersion, ServiceVersion

public class SemverVersion extends Object implements Serializable
A simple class managing a semantic version number in the format <major> "." <minor> "." <patch> "-" <pre-release> "+" <build> (where minor, patch, pre-release and build are optional) or "*" (no version specified / matches all versions).
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
    protected Integer
     
    protected Integer
     
    protected Integer
     
    protected String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SemverVersion(int major)
    generate a new ServiceVersion
    SemverVersion(int major, int minor)
    generate a new ServiceVersion
    SemverVersion(int major, int minor, int patch)
    generate a new ServiceVersion
    SemverVersion(int major, int minor, int patch, String preRelease)
    generate a new ServiceVersion
    SemverVersion(int major, int minor, int patch, String preRelease, String build)
    generate a new ServiceVersion
    Generate a Version from String representation format : Semver <major> "." <minor> "." <patch> "-" <pre-release> "+" <build> (where minor, patch, pre-release and build are optional) or "*" (no version specified / matches all versions)
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    compares to version and checks for equality
    boolean
    compares this version with any object if the given object is a String, the string representation of this version is compared to the given string
    get the build number of this (patch)version
    int
    get the major version number
    int
    get the minor version number
    int
    get the patch version of the minor version number
     
    int
    Deprecated.
    use getPatch() instead
    int
    since equals is overridden, we should implement an own hashCode.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • major

      protected Integer major
    • minor

      protected Integer minor
    • patch

      protected Integer patch
    • build

      protected String build
    • preRelease

      protected String preRelease
  • Constructor Details

    • SemverVersion

      public SemverVersion(String version) throws IllegalArgumentException
      Generate a Version from String representation format : Semver <major> "." <minor> "." <patch> "-" <pre-release> "+" <build> (where minor, patch, pre-release and build are optional) or "*" (no version specified / matches all versions)
      Parameters:
      version - A version string representation to parse
      Throws:
      IllegalArgumentException - If the string contains no valid version representation
    • SemverVersion

      public SemverVersion(int major, int minor, int patch, String preRelease, String build) throws IllegalArgumentException
      generate a new ServiceVersion
      Parameters:
      major - Major version number part
      minor - Minor version number part
      patch - Patch version number part
      preRelease - pre-release version
      build - build version
      Throws:
      IllegalArgumentException - If a version number part is smaller than 0
    • SemverVersion

      public SemverVersion(int major, int minor, int patch, String preRelease) throws IllegalArgumentException
      generate a new ServiceVersion
      Parameters:
      major - Major version number part
      minor - Minor version number part
      patch - Patch version number part
      preRelease - pre-release version
      Throws:
      IllegalArgumentException - If a version number part is smaller than 0
    • SemverVersion

      public SemverVersion(int major, int minor, int patch) throws IllegalArgumentException
      generate a new ServiceVersion
      Parameters:
      major - Major version number part
      minor - Minor version number part
      patch - Patch version number part
      Throws:
      IllegalArgumentException - If a version number part is smaller than 0
    • SemverVersion

      public SemverVersion(int major, int minor) throws IllegalArgumentException
      generate a new ServiceVersion
      Parameters:
      major - Major version number part
      minor - Minor version number part
      Throws:
      IllegalArgumentException - If a version number part is smaller than 0
    • SemverVersion

      public SemverVersion(int major) throws IllegalArgumentException
      generate a new ServiceVersion
      Parameters:
      major - Major version number part
      Throws:
      IllegalArgumentException - If a version number part is smaller than 0
  • Method Details

    • equals

      public boolean equals(SemverVersion v)
      compares to version and checks for equality
      Parameters:
      v - Another service version to compare to
      Returns:
      true, if this version is the same as the given one
    • equals

      public boolean equals(Object o)
      compares this version with any object if the given object is a String, the string representation of this version is compared to the given string
      Overrides:
      equals in class Object
      Parameters:
      o - Another object to check
      Returns:
      true, if the given object is a version and the same as this one
    • hashCode

      public int hashCode()
      since equals is overridden, we should implement an own hashCode.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code as int
    • getMinor

      public int getMinor()
      get the minor version number
      Returns:
      minor version number
    • getMajor

      public int getMajor()
      get the major version number
      Returns:
      major version number
    • getPatch

      public int getPatch()
      get the patch version of the minor version number
      Returns:
      patch version number of minor
    • getSub

      public int getSub()
      Deprecated.
      use getPatch() instead
      get the subversion of the minor version number
      Returns:
      subversion number of minor
    • getBuild

      public String getBuild()
      get the build number of this (patch)version
      Returns:
      build number
    • getPreRelease

      public String getPreRelease()
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a String representation of this version