com.springsource.util.osgi
Class VersionRange

java.lang.Object
  extended by com.springsource.util.osgi.VersionRange

public final class VersionRange
extends java.lang.Object

Parses the String specification a range of Versions as defined in ?3.2.5 of the OSGi Service Server Core Specification.

The VersionRange can be queried to see if it includes a particular Version using includes(Version).

Distinct representations of an empty range are regarded as equal.

Concurrent Semantics
Implementation is immutable.

Since:
1.0
Author:
Rob Harrop, Glyn Normington

Field Summary
private  org.osgi.framework.Version ceiling
           
private  boolean ceilingInclusive
           
private static char EXCLUSIVE_LOWER
           
private static char EXCLUSIVE_UPPER
           
private  org.osgi.framework.Version floor
           
private  boolean floorInclusive
           
private static char INCLUSIVE_LOWER
           
private static char INCLUSIVE_UPPER
           
static VersionRange NATURAL_NUMBER_RANGE
           
private static org.osgi.framework.Version ZERO_VERSION
           
 
Constructor Summary
private VersionRange(boolean floorInclusive, org.osgi.framework.Version floor, org.osgi.framework.Version ceiling, boolean ceilingInclusive)
           
  VersionRange(java.lang.String versionRange)
          Creates a VersionRange for the provided specification.
 
Method Summary
static VersionRange createExactRange(org.osgi.framework.Version version)
          Creates a VersionRange that encompasses the supplied version, and only the supplied version: [version, version].
 boolean equals(java.lang.Object object)
          
 org.osgi.framework.Version getCeiling()
          Gets the ceiling of this VersionRange.
 org.osgi.framework.Version getFloor()
          Gets the floor of this VersionRange.
 int hashCode()
          
 boolean includes(org.osgi.framework.Version version)
          Queries whether this VersionRange includes the supplied Version.
static VersionRange intersection(VersionRange rangeOne, VersionRange rangeTwo)
          Returns a VersionRange that is the intersection of the two supplied VersionRanges.
 boolean isCeilingInclusive()
          Indicates whether or not the ceiling of this VersionRange is inclusive.
 boolean isEmpty()
           
 boolean isExact()
          Queries whether this VersionRange is an exact range containing a single version.
 boolean isFloorInclusive()
          Indicates whether or not the floor of this VersionRange is inclusive.
static VersionRange naturalNumberRange()
          Creates a VersionRange encompassing all the natural numbers: [0.0.0, ?).
 java.lang.String toParseString()
          Creates a String representation of this VersionRange that can be re-parsed.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO_VERSION

private static final org.osgi.framework.Version ZERO_VERSION

INCLUSIVE_LOWER

private static final char INCLUSIVE_LOWER
See Also:
Constant Field Values

INCLUSIVE_UPPER

private static final char INCLUSIVE_UPPER
See Also:
Constant Field Values

EXCLUSIVE_LOWER

private static final char EXCLUSIVE_LOWER
See Also:
Constant Field Values

EXCLUSIVE_UPPER

private static final char EXCLUSIVE_UPPER
See Also:
Constant Field Values

NATURAL_NUMBER_RANGE

public static final VersionRange NATURAL_NUMBER_RANGE

floor

private final org.osgi.framework.Version floor

ceiling

private final org.osgi.framework.Version ceiling

floorInclusive

private final boolean floorInclusive

ceilingInclusive

private final boolean ceilingInclusive
Constructor Detail

VersionRange

public VersionRange(java.lang.String versionRange)
Creates a VersionRange for the provided specification.

Parameters:
versionRange - the VersionRange specification.

VersionRange

private VersionRange(boolean floorInclusive,
                     org.osgi.framework.Version floor,
                     org.osgi.framework.Version ceiling,
                     boolean ceilingInclusive)
Method Detail

naturalNumberRange

public static VersionRange naturalNumberRange()
Creates a VersionRange encompassing all the natural numbers: [0.0.0, ?).

Returns:
a VersionRange encompassing all the natural numbers.

createExactRange

public static VersionRange createExactRange(org.osgi.framework.Version version)
Creates a VersionRange that encompasses the supplied version, and only the supplied version: [version, version].

Parameters:
version - The version for which an exact range is required.
Returns:
The exact range.

getFloor

public org.osgi.framework.Version getFloor()
Gets the floor of this VersionRange.

Returns:
floor of this VersionRange.

getCeiling

public org.osgi.framework.Version getCeiling()
Gets the ceiling of this VersionRange. The returned Version is null if and only if this VersionRange is unbounded.

Returns:
ceiling of this VersionRange or null if the range is unbounded.

isFloorInclusive

public boolean isFloorInclusive()
Indicates whether or not the floor of this VersionRange is inclusive.

Returns:
true if the floor is inclusive; otherwise false.

isCeilingInclusive

public boolean isCeilingInclusive()
Indicates whether or not the ceiling of this VersionRange is inclusive.

Returns:
true if the ceiling is inclusive; otherwise false.

includes

public boolean includes(org.osgi.framework.Version version)
Queries whether this VersionRange includes the supplied Version.

Parameters:
version - the Version to check against.
Returns:
true if the Version is included in this VersionRange; otherwise false.

isExact

public boolean isExact()
Queries whether this VersionRange is an exact range containing a single version.

Returns:
true if and only if this code>VersionRange is exact

equals

public boolean equals(java.lang.Object object)

Overrides:
equals in class java.lang.Object

isEmpty

public boolean isEmpty()

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

toParseString

public java.lang.String toParseString()
Creates a String representation of this VersionRange that can be re-parsed.

Returns:
string representation of version range

intersection

public static VersionRange intersection(VersionRange rangeOne,
                                        VersionRange rangeTwo)
Returns a VersionRange that is the intersection of the two supplied VersionRanges.

Parameters:
rangeOne - The first VersionRange for the intersection
rangeTwo - The second VersionRange for the intersection
Returns:
The intersection of the two VersionRanges