Package org.osgi.framework
Class VersionRange
java.lang.Object
org.osgi.framework.VersionRange
Version range. A version range is an interval describing a set of
versions.
A range has a left (lower) endpoint and a right (upper) endpoint. Each endpoint can be open (excluded from the set) or closed (included in the set).
VersionRange objects are immutable.
- Since:
- 1.7
- Author:
- $Id: 1f5fa660a1a42e83371fe0d2c61ae79ce1cb1710 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe left endpoint is closed and is included in the range.static final charThe left endpoint is open and is excluded from the range.static final charThe right endpoint is closed and is included in the range.static final charThe right endpoint is open and is excluded from the range. -
Constructor Summary
ConstructorsConstructorDescriptionVersionRange(char leftType, Version leftEndpoint, Version rightEndpoint, char rightType) Creates a version range from the specified versions.VersionRange(String range) Creates a version range from the specified string. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares thisVersionRangeobject to another object.getLeft()Returns the left endpoint of this version range.charReturns the type of the left endpoint of this version range.getRight()Returns the right endpoint of this version range.charReturns the type of the right endpoint of this version range.inthashCode()Returns a hash code value for the object.booleanReturns whether this version range includes the specified version.intersection(VersionRange... ranges) Returns the intersection of this version range with the specified version ranges.booleanisEmpty()Returns whether this version range is empty.booleanisExact()Returns whether this version range contains only a single version.toFilterString(String attributeName) Returns the filter string for this version range using the specified attribute name.toString()Returns the string representation of this version range.static VersionRangeReturns aVersionRangeobject holding the version range in the specifiedString.
-
Field Details
-
LEFT_OPEN
public static final char LEFT_OPENThe left endpoint is open and is excluded from the range.The value of
LEFT_OPENis'('.- See Also:
-
LEFT_CLOSED
public static final char LEFT_CLOSEDThe left endpoint is closed and is included in the range.The value of
LEFT_CLOSEDis'['.- See Also:
-
RIGHT_OPEN
public static final char RIGHT_OPENThe right endpoint is open and is excluded from the range.The value of
RIGHT_OPENis')'.- See Also:
-
RIGHT_CLOSED
public static final char RIGHT_CLOSEDThe right endpoint is closed and is included in the range.The value of
RIGHT_CLOSEDis']'.- See Also:
-
-
Constructor Details
-
VersionRange
Creates a version range from the specified versions.- Parameters:
leftType- Must be eitherLEFT_CLOSEDorLEFT_OPEN.leftEndpoint- Left endpoint of range. Must not benull.rightEndpoint- Right endpoint of range. May benullto indicate the right endpoint is Infinity.rightType- Must be eitherRIGHT_CLOSEDorRIGHT_OPEN.- Throws:
IllegalArgumentException- If the arguments are invalid.
-
VersionRange
Creates a version range from the specified string.Version range string grammar:
range ::= interval | atleast interval ::= ( '[' | '(' ) left ',' right ( ']' | ')' ) left ::= version right ::= version atleast ::= version- Parameters:
range- String representation of the version range. The versions in the range must contain no whitespace. Other whitespace in the range string is ignored. Must not benull.- Throws:
IllegalArgumentException- Ifrangeis improperly formatted.
-
-
Method Details
-
getLeft
Returns the left endpoint of this version range.- Returns:
- The left endpoint.
-
getRight
Returns the right endpoint of this version range.- Returns:
- The right endpoint. May be
nullwhich indicates the right endpoint is Infinity.
-
getLeftType
public char getLeftType()Returns the type of the left endpoint of this version range.- Returns:
LEFT_CLOSEDif the left endpoint is closed orLEFT_OPENif the left endpoint is open.
-
getRightType
public char getRightType()Returns the type of the right endpoint of this version range.- Returns:
RIGHT_CLOSEDif the right endpoint is closed orRIGHT_OPENif the right endpoint is open.
-
includes
Returns whether this version range includes the specified version.- Parameters:
version- The version to test for inclusion in this version range.- Returns:
trueif the specified version is included in this version range;falseotherwise.
-
intersection
Returns the intersection of this version range with the specified version ranges.- Parameters:
ranges- The version ranges to intersect with this version range.- Returns:
- A version range representing the intersection of this version range and the specified version ranges. If no version ranges are specified, then this version range is returned.
-
isEmpty
public boolean isEmpty()Returns whether this version range is empty. A version range is empty if the set of versions defined by the interval is empty.- Returns:
trueif this version range is empty;falseotherwise.
-
isExact
public boolean isExact()Returns whether this version range contains only a single version.- Returns:
trueif this version range contains only a single version;falseotherwise.
-
toString
Returns the string representation of this version range.The format of the version range string will be a version string if the right end point is Infinity (
null) or an interval string. -
hashCode
public int hashCode()Returns a hash code value for the object. -
equals
Compares thisVersionRangeobject to another object.A version range is considered to be equal to another version range if both the endpoints and their types are equal or if both version ranges are
empty. -
toFilterString
Returns the filter string for this version range using the specified attribute name.- Parameters:
attributeName- The attribute name to use in the returned filter string.- Returns:
- A filter string for this version range using the specified attribute name.
- Throws:
IllegalArgumentException- If the specified attribute name is not a valid attribute name.- See Also:
-
valueOf
Returns aVersionRangeobject holding the version range in the specifiedString.See
VersionRange(String)for the format of the version range string.- Parameters:
range- String representation of the version range. The versions in the range must contain no whitespace. Other whitespace in the range string is ignored. Must not benull.- Returns:
- A
VersionRangeobject representing the version range. - Throws:
IllegalArgumentException- Ifrangeis improperly formatted.- Since:
- 1.8
-