类 Version

  • 所有已实现的接口:
    java.lang.Comparable<Version>

    public class Version
    extends java.lang.Object
    implements java.lang.Comparable<Version>
    Version identifier for capabilities such as bundles and packages.

    Version identifiers have four components.

    1. Major version. A non-negative integer.
    2. Minor version. A non-negative integer.
    3. Micro version. A non-negative integer.
    4. Qualifier. A text string. See Version(String) for the format of the qualifier string.

    Version objects are immutable.

    从以下版本开始:
    1.3
    作者:
    $Id: c24d4d37a0657ac69de29085d2d290cbb0031c4a $
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static Version emptyVersion
      The empty version "0.0.0".
    • 构造器概要

      构造器 
      构造器 说明
      Version​(int major, int minor, int micro)
      Creates a version identifier from the specified numerical components.
      Version​(int major, int minor, int micro, java.lang.String qualifier)
      Creates a version identifier from the specified components.
      Version​(java.lang.String version)
      Creates a version identifier from the specified string.
    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      int compareTo​(Version other)
      Compares this Version object to another Version.
      boolean equals​(java.lang.Object object)
      Compares this Version object to another object.
      int getMajor()
      Returns the major component of this version identifier.
      int getMicro()
      Returns the micro component of this version identifier.
      int getMinor()
      Returns the minor component of this version identifier.
      java.lang.String getQualifier()
      Returns the qualifier component of this version identifier.
      int hashCode()
      Returns a hash code value for the object.
      static Version parseVersion​(java.lang.String version)
      Parses a version identifier from the specified string.
      java.lang.String toString()
      Returns the string representation of this version identifier.
      static Version valueOf​(java.lang.String version)
      Returns a Version object holding the version identifier in the specified String.
      • 从类继承的方法 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 字段详细资料

      • emptyVersion

        public static final Version emptyVersion
        The empty version "0.0.0".
    • 构造器详细资料

      • Version

        public Version​(int major,
                       int minor,
                       int micro)
        Creates a version identifier from the specified numerical components.

        The qualifier is set to the empty string.

        参数:
        major - Major component of the version identifier.
        minor - Minor component of the version identifier.
        micro - Micro component of the version identifier.
        抛出:
        java.lang.IllegalArgumentException - If the numerical components are negative.
      • Version

        public Version​(int major,
                       int minor,
                       int micro,
                       java.lang.String qualifier)
        Creates a version identifier from the specified components.
        参数:
        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.
        抛出:
        java.lang.IllegalArgumentException - If the numerical components are negative or the qualifier string is invalid.
      • Version

        public Version​(java.lang.String version)
        Creates a version identifier from the specified string.

        Version string grammar:

         version ::= major('.'minor('.'micro('.'qualifier)?)?)?
         major ::= digit+
         minor ::= digit+
         micro ::= digit+
         qualifier ::= (alpha|digit|'_'|'-')+
         digit ::= [0..9]
         alpha ::= [a..zA..Z]
         
        参数:
        version - String representation of the version identifier. There must be no whitespace in the argument.
        抛出:
        java.lang.IllegalArgumentException - If version is improperly formatted.
    • 方法详细资料

      • parseVersion

        public static Version parseVersion​(java.lang.String version)
        Parses a version identifier from the specified string.

        See Version(String) for the format of the version string.

        参数:
        version - String representation of the version identifier. Leading and trailing whitespace will be ignored.
        返回:
        A Version object representing the version identifier. If version is null or the empty string then emptyVersion will be returned.
        抛出:
        java.lang.IllegalArgumentException - If version is improperly formatted.
      • valueOf

        public static Version valueOf​(java.lang.String version)
        Returns a Version object holding the version identifier in the specified String.

        See Version(String) for the format of the version string.

        This method performs a similar function as parseVersion(String) but has the static factory valueOf(String) method signature.

        参数:
        version - String representation of the version identifier. Leading and trailing whitespace will be ignored. Must not be null.
        返回:
        A Version object representing the version identifier. If version is the empty string then emptyVersion will be returned.
        抛出:
        java.lang.IllegalArgumentException - If version is improperly formatted.
        从以下版本开始:
        1.8
      • getMajor

        public int getMajor()
        Returns the major component of this version identifier.
        返回:
        The major component.
      • getMinor

        public int getMinor()
        Returns the minor component of this version identifier.
        返回:
        The minor component.
      • getMicro

        public int getMicro()
        Returns the micro component of this version identifier.
        返回:
        The micro component.
      • getQualifier

        public java.lang.String getQualifier()
        Returns the qualifier component of this version identifier.
        返回:
        The qualifier component.
      • toString

        public java.lang.String toString()
        Returns the string representation of this version identifier.

        The format of the version string will be major.minor.micro if qualifier is the empty string or major.minor.micro.qualifier otherwise.

        覆盖:
        toString 在类中 java.lang.Object
        返回:
        The string representation of this version identifier.
      • hashCode

        public int hashCode()
        Returns a hash code value for the object.
        覆盖:
        hashCode 在类中 java.lang.Object
        返回:
        An integer which is a hash code value for this object.
      • equals

        public boolean equals​(java.lang.Object object)
        Compares this Version object to another object.

        A version is considered to be equal to another version if the major, minor and micro components are equal and the qualifier component is equal (using String.equals).

        覆盖:
        equals 在类中 java.lang.Object
        参数:
        object - The Version object to be compared.
        返回:
        true if object is a Version and is equal to this object; false otherwise.
      • compareTo

        public int compareTo​(Version other)
        Compares this Version object to another Version.

        A version is considered to be less than another version if its major component is less than the other version's major component, or the major components are equal and its minor component is less than the other version's minor component, or the major and minor components are equal and its micro component is less than the other version's micro component, or the major, minor and micro components are equal and it's qualifier component is less than the other version's qualifier component (using String.compareTo).

        A version is considered to be equal to another version if the major, minor and micro components are equal and the qualifier component is equal (using String.compareTo).

        指定者:
        compareTo 在接口中 java.lang.Comparable<Version>
        参数:
        other - The Version object to be compared.
        返回:
        A negative integer, zero, or a positive integer if this version is less than, equal to, or greater than the specified Version object.
        抛出:
        java.lang.ClassCastException - If the specified object is not a Version object.