java.module
Class Version

java.lang.Object
  extended by java.module.Version
All Implemented Interfaces:
Comparable<Version>

public class Version
extends Object
implements Comparable<Version>

This class represents a version in the module system. The version must be in the following format:

    major[.minor[.micro[.update]]][-qualifier]
 
For example,
    1
    1.7
    1.7-b61
    1.7.0
    1.7.0-b61
    1.7.0.0
    1.7.0.1
    1.7.1.3-b32-beta-1
    1.7.1.3-b56_rc
 
The version format is described by the following grammar:
    version := simple-version ('-' qualifier)?
    simple-version:= major ('.' minor ('.' micro ('.' update)?)?)?
    major := digit+
    minor := digit+
    micro := digit+
    update := digit+
    qualifier := (alpha | digit | '-' | '_')+
 
where alpha is an alphabetic character, e.g. a-z, A-Z. digit is a decimal digit, e.g. 0-9.

Instances of this class are immutable and safe for concurrent use by multiple threads.

Since:
1.7
Author:
Stanley M. Ho
See Also:
Query, VersionConstraint

Field Summary
static Version DEFAULT
          A Version object that represents the default version "0.0.0.0-default".
 
Constructor Summary
protected Version(int major, int minor, int micro, int update, String qualifier)
          Constructs a new Version instance.
 
Method Summary
 int compareTo(Version version)
          Compare two Version objects.
 boolean equals(Object obj)
          Compare two Version objects for equality.
 int getMajorNumber()
          Returns the major number in the version.
 int getMicroNumber()
          Returns the micro number in the version.
 int getMinorNumber()
          Returns the minor number in the version.
 String getQualifier()
          Returns the qualifier in the version.
 int getUpdateNumber()
          Returns the update number in the version.
 int hashCode()
          Returns a hash code for this Version.
static boolean isVersion(String source)
          Returns true if the string is a version in valid format.
 String toString()
          Returns a String object representing this Version's value.
 VersionConstraint toVersionConstraint()
          Return a VersionConstraint object that represents this version.
 Version trimQualifier()
          Returns a Version instance, with the qualifier omitted.
static Version valueOf(int major, int minor, int micro)
          Returns a Version object holding the specified version number.
static Version valueOf(int major, int minor, int micro, int update)
          Returns a Version object holding the specified version number.
static Version valueOf(int major, int minor, int micro, int update, String qualifier)
          Returns a Version object holding the specified version number.
static Version valueOf(int major, int minor, int micro, String qualifier)
          Returns a Version object holding the specified version number.
static Version valueOf(String version)
          Returns a Version object holding the value of the specified string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final Version DEFAULT
A Version object that represents the default version "0.0.0.0-default".

Constructor Detail

Version

protected Version(int major,
                  int minor,
                  int micro,
                  int update,
                  String qualifier)
Constructs a new Version instance. This constructor is for use by subclasses. Applications should use one of the valueOf() factory methods to obtain Version instances.

Parameters:
major - the major version number.
minor - the minor version number.
micro - the micro version number.
update - the update version number.
qualifier - the qualifier
Throws:
IllegalArgumentException - if major, minor, micro, or update are negative, or if qualifier contains illegal character.
Method Detail

valueOf

public static Version valueOf(String version)
Returns a Version object holding the value of the specified string. The string must be in the version format and must not contain any leading or trailing whitespace.

Parameters:
version - the string to be parsed.
Returns:
a Version parsed from the string.
Throws:
IllegalArgumentException - if the string cannot be parsed.

valueOf

public static Version valueOf(int major,
                              int minor,
                              int micro)
Returns a Version object holding the specified version number.

Equivalent to valueOf(major, minor, micro, 0, null);.

Parameters:
major - the major version number.
minor - the minor version number.
micro - the micro version number.
Throws:
IllegalArgumentException - if major, minor, or micro is negative.

valueOf

public static Version valueOf(int major,
                              int minor,
                              int micro,
                              String qualifier)
Returns a Version object holding the specified version number.

Equivalent to valueOf(major, minor, micro, 0, qualifier);.

Parameters:
major - the major version number.
minor - the minor version number.
micro - the micro version number.
qualifier - the qualifier
Throws:
IllegalArgumentException - if major or minor or micro is negative, or qualifier contains illegal character.

valueOf

public static Version valueOf(int major,
                              int minor,
                              int micro,
                              int update)
Returns a Version object holding the specified version number.

Equivalent to valueOf(major, minor, micro, update, null);.

Parameters:
major - the major version number.
minor - the minor version number.
micro - the micro version number.
update - the update version number.
Throws:
IllegalArgumentException - if major or minor or micro or update is negative.

valueOf

public static Version valueOf(int major,
                              int minor,
                              int micro,
                              int update,
                              String qualifier)
Returns a Version object holding the specified version number.

Parameters:
major - the major version number.
minor - the minor version number.
micro - the micro version number.
update - the update version number.
qualifier - the qualifier
Throws:
IllegalArgumentException - if major, minor, micro, or update is negative, or if qualifier contains illegal characters.

getMajorNumber

public int getMajorNumber()
Returns the major number in the version.

Returns:
the major version.

getMinorNumber

public int getMinorNumber()
Returns the minor number in the version.

Returns:
the minor version.

getMicroNumber

public int getMicroNumber()
Returns the micro number in the version.

Returns:
the micro version.

getUpdateNumber

public int getUpdateNumber()
Returns the update number in the version.

Returns:
the update version.

getQualifier

public String getQualifier()
Returns the qualifier in the version.

Returns:
the qualifier.

isVersion

public static boolean isVersion(String source)
Returns true if the string is a version in valid format.

Returns:
true if the string is a version in valid format. Otherwise, returns false.

toVersionConstraint

public VersionConstraint toVersionConstraint()
Return a VersionConstraint object that represents this version.

Returns:
a VersionConstraint object.

compareTo

public int compareTo(Version version)
Compare two Version objects.

Specified by:
compareTo in interface Comparable<Version>
Parameters:
version - the Version to be compared.
Returns:
the value 0 if the argument Version is equal to this Version; a value less than 0 if this Version is less than the Version argument; and a value greater than 0 if this Version is greater than the Version argument.

trimQualifier

public Version trimQualifier()
Returns a Version instance, with the qualifier omitted.


equals

public boolean equals(Object obj)
Compare two Version objects for equality. The result is true if and only if the argument is not null and is a Version object that the major, minor, micro, update, and qualifier the same as those of this Version.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
whether or not the two objects are equal

hashCode

public int hashCode()
Returns a hash code for this Version.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.

toString

public String toString()
Returns a String object representing this Version's value. The value is converted to the version format and returned as a string.

Overrides:
toString in class Object
Returns:
a string representation of the value of this object in the version format.