java.module
Class VersionConstraint

java.lang.Object
  extended by java.module.VersionConstraint

public final class VersionConstraint
extends Object

This class represents a version constraint in the module system. A version constraint is either a version, a version range, or combination of both.

For example,

    Version:
    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

    General version range:
    [1.2.3.4, 5.6.7.8)        ~ 1.2.3.4 <= x < 5.6.7.8
    (1.2.3.4, 5.6.7.8]        ~ 1.2.3.4 < x <= 5.6.7.8
    (1.2.3.4, 5.6.7.8)        ~ 1.2.3.4 < x < 5.6.7.8
    [1.2.3.4, 5.6.7.8]        ~ 1.2.3.4 <= x <= 5.6.7.8

    Open version range:
    1+                        ~ [1, infinity)                 ~ 1 <= x < infinity
    1.2+                      ~ [1.2, infinity)               ~ 1.2 <= x < infinity
    1.2.3+                    ~ [1.2.3, infinity)             ~ 1.2.3 <= x < infinity
    1.2.3.4+                  ~ [1.2.3.4, infinity)           ~ 1.2.3.4 <= x < infinity

    Family version range:
    1.*                       ~ [1, 2)                        ~ 1 <= x < 2
    1.2.*                     ~ [1.2, 1.3)                    ~ 1.2 <= x < 1.3
    1.2.3.*                   ~ [1.2.3, 1.2.4)                ~ 1.2.3 <= x < 1.2.4 

    Union of ranges:
    [1.2.3.4, 2.0);2.*;3+     ~ 1.2.3.4 <= x < infinity 
    1.*;[2.0, 2.7.3)          ~ 1.0.0 <= x < 2.7.3
 
The version constraint format is described by the following grammar:
   version-constraint := simple-version-constraint (';' simple-version-constraint)*
   simple-version-constraint := version | version-range
   
   version-range := simple-version-range (';' simple-version-range)*
   simple-version-range := general-version-range | open-version-range | family-version-range
   general-version-range := ('[' | '(') simple-version ',' simple-version (')' | ']')
   open-version-range := simple-version '+'
   family-version-range := major '.' (minor '.' (micro '.')?)? '*' 
   
   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.

Applications can obtain VersionConstraint objects by calling the valueOf() factory method.

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

Since:
1.7
Author:
Stanley M. Ho
See Also:
Version

Field Summary
static VersionConstraint DEFAULT
          A VersionConstraint object that represents the default version constraint that is "0.0.0.0+".
 
Method Summary
 boolean contains(Version version)
          Returns true if the specified Version is contained within any of the ranges known to this VersionConstraint.
 boolean contains(VersionConstraint versionConstraint)
          Returns true if the specified VersionConstraint is contained within any of the ranges known to this VersionConstraint.
 boolean equals(Object obj)
          Compare two VersionConstraint objects for equality.
 int hashCode()
          Returns a hash code for this VersionConstraint.
 String toString()
          Returns a String object representing this VersionConstraint's value.
static VersionConstraint valueOf(String versionConstraint)
          Returns a VersionConstraint 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 VersionConstraint DEFAULT
A VersionConstraint object that represents the default version constraint that is "0.0.0.0+".

Method Detail

contains

public boolean contains(Version version)
Returns true if the specified Version is contained within any of the ranges known to this VersionConstraint.

Parameters:
version - the Version object.
Returns:
true if the specified version is contained within any of ranges known to this version constraint. Otherwise, returns false.

contains

public boolean contains(VersionConstraint versionConstraint)
Returns true if the specified VersionConstraint is contained within any of the ranges known to this VersionConstraint.

Parameters:
versionConstraint - the VersionConstraint object.
Returns:
true if the specified version constraint is contained within any of ranges known to this version constraint. Otherwise, returns false.

valueOf

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

Parameters:
versionConstraint - the string to be parsed.
Returns:
A VersionConstraint parsed from the string.
Throws:
IllegalArgumentException - if the string cannot be parsed.

equals

public boolean equals(Object obj)
Compare two VersionConstraint objects for equality. The result is true if and only if the argument is not null and is a VersionConstraint object that it has the same normalized versions and version ranges as those of this VersionConstraint.

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

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

toString

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

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