Top Description Fields Constructors Methods
org.osgi.framework

public Class Version

extends Object
implements Comparable<Version>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.util.NoSuchElementException, .StringTokenizer

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.

Author
$Id: 2a5e4b8c63928ffda304dfe523fc06df49c68eae $
Since
1.3

Field Summary

Modifier and TypeField and Description
public static final Version
emptyVersion

The empty version "0.0.0".

private transient int
private final int
private final int
private final int
private final String
private static final String
private transient String

Constructor Summary

AccessConstructor and Description
public
Version(int
Major component of the version identifier.
major
,
int
Minor component of the version identifier.
minor
,
int
Micro component of the version identifier.
micro
)

Creates a version identifier from the specified numerical components.

public
Version(int
Major component of the version identifier.
major
,
int
Minor component of the version identifier.
minor
,
int
Micro component of the version identifier.
micro
,
String
Qualifier component of the version identifier. If null is specified, then the qualifier will be set to the empty string.
qualifier
)

Creates a version identifier from the specified components.

public
Version(String
String representation of the version identifier. There must be no whitespace in the argument.
version
)

Creates a version identifier from the specified string.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

A negative integer, zero, or a positive integer if this version is less than, equal to, or greater than the specified Version object.
compareTo
(Version
The Version object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this Version object to another Version.

public boolean

Returns:

true if object is a Version and is equal to this object; false otherwise.
equals
(Object
The Version object to be compared.
object
)

Overrides java.lang.Object.equals.

Compares this Version object to another object.

public int

Returns:

The major component.
getMajor
()

Returns the major component of this version identifier.

public int

Returns:

The micro component.
getMicro
()

Returns the micro component of this version identifier.

public int

Returns:

The minor component.
getMinor
()

Returns the minor component of this version identifier.

public String

Returns:

The qualifier component.
getQualifier
()

Returns the qualifier component of this version identifier.

public int

Returns:

An integer which is a hash code value for this object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.

private static int

Returns:

int value of numeric component
parseInt
(String
Numeric component
value
,
String
Complete version string for exception message, if any
version
)

Parse numeric component into an int.

public static Version

Returns:

A Version object representing the version identifier. If version is null or the empty string then emptyVersion will be returned.
parseVersion
(String
String representation of the version identifier. Leading and trailing whitespace will be ignored.
version
)

Parses a version identifier from the specified string.

public String

Returns:

The string representation of this version identifier.
toString
()

Overrides java.lang.Object.toString.

Returns the string representation of this version identifier.

pack-priv String

Returns:

The string representation of this version identifier.
toString0
()

Internal toString behavior

private void
validate()

Called by the Version constructors to validate the version components.

public static Version

Returns:

A Version object representing the version identifier. If version is the empty string then emptyVersion will be returned.
valueOf
(String
String representation of the version identifier. Leading and trailing whitespace will be ignored. Must not be null.
version
)

Returns a Version object holding the version identifier in the specified String.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

emptyVersionback to summary
public static final Version emptyVersion

The empty version "0.0.0".

hashback to summary
private transient int hash
majorback to summary
private final int major
microback to summary
private final int micro
minorback to summary
private final int minor
qualifierback to summary
private final String qualifier
SEPARATORback to summary
private static final String SEPARATOR
versionStringback to summary
private transient String versionString

Constructor Detail

Versionback to summary
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.

Parameters
major:int

Major component of the version identifier.

minor:int

Minor component of the version identifier.

micro:int

Micro component of the version identifier.

Exceptions
IllegalArgumentException:
If the numerical components are negative.
Versionback to summary
public Version(int major, int minor, int micro, String qualifier)

Creates a version identifier from the specified components.

Parameters
major:int

Major component of the version identifier.

minor:int

Minor component of the version identifier.

micro:int

Micro component of the version identifier.

qualifier:String

Qualifier component of the version identifier. If null is specified, then the qualifier will be set to the empty string.

Exceptions
IllegalArgumentException:
If the numerical components are negative or the qualifier string is invalid.
Versionback to summary
public Version(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]
Parameters
version:String

String representation of the version identifier. There must be no whitespace in the argument.

Exceptions
IllegalArgumentException:
If version is improperly formatted.

Method Detail

compareToback to summary
public int compareTo(Version other)

Implements java.lang.Comparable.compareTo.

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).

Parameters
other:Version

The Version object to be compared.

Returns:int

A negative integer, zero, or a positive integer if this version is less than, equal to, or greater than the specified Version object.

Annotations
@Override
Exceptions
ClassCastException:
If the specified object is not a Version object.
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

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).

Parameters
object:Object

The Version object to be compared.

Returns:boolean

true if object is a Version and is equal to this object; false otherwise.

Annotations
@Override
getMajorback to summary
public int getMajor()

Returns the major component of this version identifier.

Returns:int

The major component.

getMicroback to summary
public int getMicro()

Returns the micro component of this version identifier.

Returns:int

The micro component.

getMinorback to summary
public int getMinor()

Returns the minor component of this version identifier.

Returns:int

The minor component.

getQualifierback to summary
public String getQualifier()

Returns the qualifier component of this version identifier.

Returns:String

The qualifier component.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.

Returns:int

An integer which is a hash code value for this object.

Annotations
@Override
parseIntback to summary
private static int parseInt(String value, String version)

Parse numeric component into an int.

Parameters
value:String

Numeric component

version:String

Complete version string for exception message, if any

Returns:int

int value of numeric component

parseVersionback to summary
public static Version parseVersion(String version)

Parses a version identifier from the specified string.

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

Parameters
version:String

String representation of the version identifier. Leading and trailing whitespace will be ignored.

Returns:Version

A Version object representing the version identifier. If version is null or the empty string then emptyVersion will be returned.

Exceptions
IllegalArgumentException:
If version is improperly formatted.
toStringback to summary
public String toString()

Overrides java.lang.Object.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.

Returns:String

The string representation of this version identifier.

Annotations
@Override
toString0back to summary
pack-priv String toString0()

Internal toString behavior

Returns:String

The string representation of this version identifier.

validateback to summary
private void validate()

Called by the Version constructors to validate the version components.

Exceptions
IllegalArgumentException:
If the numerical components are negative or the qualifier string is invalid.
valueOfback to summary
public static Version valueOf(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.

Parameters
version:String

String representation of the version identifier. Leading and trailing whitespace will be ignored. Must not be null.

Returns:Version

A Version object representing the version identifier. If version is the empty string then emptyVersion will be returned.

Exceptions
IllegalArgumentException:
If version is improperly formatted.
Since
1.8