Class Version

java.lang.Object
org.eclipse.equinox.p2.metadata.Version
All Implemented Interfaces:
Serializable, Comparable<Version>

public abstract class Version extends Object implements Comparable<Version>, Serializable
A class that represents a Version in the Omni Version format. A Version can be thought of as an array of comparable elements and an optional pad value. The pad value is used when comparing two versions with a different number of segments. The Omni Version can convert almost any version into a raw format that it uses for comparisons. This enables a unified order of all such versions and solves problems that arise when the version semantics are different. A good example is the OSGi version versus the version used in Maven. The lack of qualifier in the OSGi version implies that the qualifier is an empty string. So a version without a qualifier is the smallest of all other versions with the same major,minor,micro number. With Maven semantics, it's the opposite. If the qualifier is removed, the resulting version is considered higher then all other versions with the same major, minor, and micro number. The Omni version solves this by using different raw representations of the OSGi and Maven versions. The Omni version addresses a lot of other issues as well, such as reordering of the elements or treating some parts of a version as irrelevant when comparing. The class is signature compatible with Version but attempts to use it as such might render a UnsupportedOperationException in case the raw vector holds incompatible values. The method isOSGiCompatible() can be used to test.
Since:
2.0
See Also:
Restriction:
This class is not intended to be subclassed by clients.
  • Field Details

    • RAW_PREFIX

      public static final String RAW_PREFIX
      See Also:
    • MAX_VERSION

      public static final Version MAX_VERSION
      The version that is semantically greater then all other versions.
    • emptyVersion

      public static final Version emptyVersion
      The version that is semantically less then all other versions.
  • Constructor Details

    • Version

      public Version()
  • Method Details

    • compile

      public static IVersionFormat compile(String format) throws VersionFormatException
      Compile a version format string into a compiled format..
      Parameters:
      format - The format to compile.
      Returns:
      The compiled format
      Throws:
      VersionFormatException - If the format could not be compiled
    • create

      public static Version create(String version)
      Parses a version identifier from the specified string.

      Note that this method performs a non thread-safe object pooling. Instances are stored in a weak cache, i.e. for multiple calls with the same input it is likely but not guaranteed that the same instance is retrieved. Same holds for concurrent access on this method. Clients must not assume to get the same instance for subsequent calls.

      Parameters:
      version - String representation of the version identifier. Leading and trailing whitespace will be ignored.
      Returns:
      A Version object representing the version identifier or null if version is null or an empty string.
      Throws:
      IllegalArgumentException - If version is improperly formatted.
    • createOSGi

      public static Version createOSGi(int major, int minor, int micro)
      Creates an OSGi version identifier from the specified numerical components.

      The qualifier is set to the empty string.

      Parameters:
      major - Major component of the version identifier.
      minor - Minor component of the version identifier.
      micro - Micro component of the version identifier.
      Throws:
      IllegalArgumentException - If the numerical components are negative.
    • createOSGi

      public static Version createOSGi(int major, int minor, int micro, String qualifier)
      Creates an OSGi version identifier from the specified components.
      Parameters:
      major - Major component of the version identifier.
      minor - Minor component of the version identifier.
      micro - Micro component of the version identifier.
      qualifier - Qualifier component of the version identifier. If null is specified, then the qualifier will be set to the empty string.
      Throws:
      IllegalArgumentException - If the numerical components are negative or the qualifier string is invalid.
    • parseVersion

      public static Version parseVersion(String version)
      Parses a version identifier from the specified string. This method is for backward compatibility with OSGi and will return the OSGi "0.0.0" version when the provided string is empty or null.
      Parameters:
      version - String representation of the version identifier. Leading and trailing whitespace will be ignored.
      Returns:
      A Version object representing the version identifier. If version is null or the empty string then the OSGi emptyVersion will be returned.
      Throws:
      IllegalArgumentException - If version is improperly formatted.
      See Also:
    • getFormat

      public abstract IVersionFormat getFormat()
      Returns the optional format.
    • getOriginal

      public abstract String getOriginal()
      Returns the original part of the string for this version or null if no such part was provided when the version was created. An OSGi type version will always return the OSGi string representation.
      Returns:
      The original part of the version string or null if that part was missing.
    • getPad

      public abstract Comparable<?> getPad()
      Returns the pad value used when comparing this versions to versions that has a larger number of segments
      Returns:
      The pad value or null if not set.
    • getSegment

      public abstract Comparable<?> getSegment(int index)
      An element from the raw vector representation of this version.
      Parameters:
      index - The zero based index of the desired element
      Returns:
      An element from the raw vector
    • getSegmentCount

      public abstract int getSegmentCount()
      Returns the number of elements in the raw vector representation of this version.
      Returns:
      The number of elements in the raw vector.
    • isOSGiCompatible

      public abstract boolean isOSGiCompatible()
      Checks if this version is in compliance with the OSGi version spec.
      Returns:
      A flag indicating whether the version is OSGi compatible or not.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      @Deprecated(since="2.9") public void toString(StringBuffer sb)
      Deprecated.
      Appends the string representation of this version onto the sb StringBuffer.
      Parameters:
      sb - The buffer that will receive the version string
    • toString

      public abstract void toString(StringBuilder sb)
      Appends the string representation of this version onto the sb StringBuilder.
      Parameters:
      sb - The builder that will receive the version string
      Since:
      2.9