Class ServiceVersion

java.lang.Object
i5.las2peer.api.SemverVersion
i5.las2peer.api.p2p.ServiceVersion
All Implemented Interfaces:
Serializable, Comparable<ServiceVersion>

public class ServiceVersion extends SemverVersion implements Comparable<ServiceVersion>
A simple class managing a service 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:
  • Constructor Details

    • ServiceVersion

      public ServiceVersion(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
    • ServiceVersion

      public ServiceVersion(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
    • ServiceVersion

      public ServiceVersion(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
    • ServiceVersion

      public ServiceVersion(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
    • ServiceVersion

      public ServiceVersion(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
    • ServiceVersion

      public ServiceVersion(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

    • isLargerThan

      public boolean isLargerThan(ServiceVersion v)
      check if this version is larger than the given one
      Parameters:
      v - Another service version to compare to
      Returns:
      true, if this version is larger than the given one
    • isSmallerThan

      public boolean isSmallerThan(ServiceVersion v)
      check if this version is smaller than the given one
      Parameters:
      v - Another service version to compare to
      Returns:
      true, if this version is smaller than the given one
    • isLargerOrEqual

      public boolean isLargerOrEqual(ServiceVersion v)
      check if this version is larger than or equal to the given one
      Parameters:
      v - Another service version to compare to
      Returns:
      true, if this version is larger than or equal to the given one
    • isSmallerOrEqual

      public boolean isSmallerOrEqual(ServiceVersion v)
      check if this version is smaller than or equal to the given one
      Parameters:
      v - Another service version to compare to
      Returns:
      true, if this version is smaller than or equal to the given one
    • isBetween

      public boolean isBetween(ServiceVersion smaller, ServiceVersion larger)
      check if this version is between the given ones
      Parameters:
      smaller - A smaller service version to check for
      larger - A larger service version to check for
      Returns:
      true, if this version is between the two given ones
    • isBetween

      public boolean isBetween(String smaller, String larger)
      tries to create a version number from the given strings and compares them to this version
      Parameters:
      smaller - A smaller service version to check for
      larger - A larger service version to check for
      Returns:
      true, if this version is between the two given ones
    • compareTo

      public int compareTo(ServiceVersion other)
      implementation of Comparable
      Specified by:
      compareTo in interface Comparable<ServiceVersion>
      Parameters:
      other - Another service version to check
      Returns:
      comparison code
    • fits

      public boolean fits(ServiceVersion required)
      checks if this version "fits" to the required version e.g. "1.5.2-123" will fit "1.5", but "1.5" won't fit "1.6" or "1.5.2"
      Parameters:
      required - A required service version to check for
      Returns:
      Returns true if this version fits the required version
    • chooseFittingVersion

      public ServiceVersion chooseFittingVersion(ServiceVersion[] available)
      returns the newest ServiceVersion from all available ServiceVersions that fits this version
      Parameters:
      available - available versions
      Returns:
      a fitting ServiceVersion or null if no fitting version exists