Class Version

java.lang.Object
de.iip_ecosphere.platform.support.Version
All Implemented Interfaces:
Comparable<Version>

public class Version extends Object implements Comparable<Version>
Artifact or service version. The format in terms of a pseudo "regular expression" number is ("." number)*.
Author:
Holger Eichelberger, SSE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Pattern
     
    private int[]
     
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Version(int... version)
    Version created from version segments.
    Version(String version)
    Creates a new version by parsing a string.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    compare(Version version1, Version version2)
    Compares two versions considering null for both parameters and results in: -1 : this is smaller <=> given version and this is bigger.
    int
    compareTo(Version version)
    Compares two versions and results in: -1 : this is smaller <=> given version and this is bigger.
    static boolean
    equals(Version version1, Version version2)
    Returns whether two versions are equal.
    boolean
     
    int
    getSegment(int index)
    Returns the version segment specified by index.
    int
    Returns the number of the segments.
    int
     
    static final boolean
    isVersion(String string)
    Returns whether the given string denotes a version.
    Returns a textual representation of this instance.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • Version

      public Version(String version) throws IllegalArgumentException
      Creates a new version by parsing a string.
      Parameters:
      version - the version string in form empty or i(.i)* with i integer numbers
      Throws:
      IllegalArgumentException - in case of format problems
    • Version

      public Version(int... version)
      Version created from version segments.
      Parameters:
      version - version number segments (from left to right), without SEPARATOR
  • Method Details

    • isVersion

      public static final boolean isVersion(String string)
      Returns whether the given string denotes a version.
      Parameters:
      string - the string to be tested
      Returns:
      trueif string is a version, false else
    • getSegmentCount

      public int getSegmentCount()
      Returns the number of the segments.
      Returns:
      the number of segments
    • getSegment

      public int getSegment(int index)
      Returns the version segment specified by index.
      Parameters:
      index - a 0-based index specifying the segment to be returned
      Returns:
      the specified segment
      Throws:
      IndexOutOfBoundsException - if index<0 || index>=getSegmentCount()
    • compareTo

      public int compareTo(Version version)
      Compares two versions and results in: -1 : this is smaller <=> given version and this is bigger. 0 : given version and this are equal. +1 : this is bigger <=> given version is smaller.
      Specified by:
      compareTo in interface Comparable<Version>
      Parameters:
      version - version to compare.
      Returns:
      result in {-1, 0, 1}.
    • toString

      public String toString()
      Returns a textual representation of this instance.
      Overrides:
      toString in class Object
      Returns:
      a textual representation
    • equals

      public static boolean equals(Version version1, Version version2)
      Returns whether two versions are equal.
      Parameters:
      version1 - the first version instance (may be null)
      version2 - the second version instance (may be null)
      Returns:
      true if version1 equals version2, false else
    • compare

      public static int compare(Version version1, Version version2)
      Compares two versions considering null for both parameters and results in: -1 : this is smaller <=> given version and this is bigger. 0 : given version and this are equal. +1 : this is bigger <=> given version is smaller.
      Parameters:
      version1 - the first version to compare.
      version2 - the second version to compare.
      Returns:
      result in {-1, 0, 1}.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object