Package com.helger.commons.version
Class VersionRange
java.lang.Object
com.helger.commons.version.VersionRange
- All Implemented Interfaces:
IComparable<VersionRange>,Comparable<VersionRange>
This class represents a range of versions. Each range needs at least a lower
bound but can as well have an upper bound. See OSGi v4 reference 3.2.5
- Author:
- Philip Helger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVersionRange(Version aFloorVersion, boolean bIncludeFloorVersion, Version aCeilingVersion, boolean bIncludeCeilingVersion) Create a new version range depicted by two versions.VersionRange(Version aFloorVersion, Version aCeilingVersion) Create a new version range depicted by two versions, assuming that both the floor and the ceiling version should be included meaning we have an inclusive interval. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(VersionRange rhs) Compare this version range to another version range.booleanConverts the version range to a string.getAsString(boolean bPrintZeroElements) Converts the version range to a string.inthashCode()booleanbooleanstatic VersionRangeConstruct a version range object from a string.
Examples:
[1.2.3, 4.5.6) -- 1.2.3 <= x < 4.5.6 [1.2.3, 4.5.6] -- 1.2.3 <= x <= 4.5.6 (1.2.3, 4.5.6) -- 1.2.3 < x < 4.5.6 (1.2.3, 4.5.6] -- 1.2.3 < x <= 4.5.6 1.2.3 -- 1.2.3 <= x [1.2.3 -- 1.2.3 <= x (1.2.3 -- 1.2.3 < x null -- 0.0.0 <= x 1, 4 -- 1 <= x <= 4toString()booleanversionMatches(Version rhs)
-
Field Details
-
DEFAULT_VERSION_RANGE_STRING
Default version range string.- See Also:
-
-
Constructor Details
-
VersionRange
Create a new version range depicted by two versions, assuming that both the floor and the ceiling version should be included meaning we have an inclusive interval.- Parameters:
aFloorVersion- the floor version of the range - may not be nullaCeilingVersion- the ceiling version of the range - may be null- Throws:
IllegalArgumentException- if the floor version to be used is > the ceiling version or if the floor version is null.
-
VersionRange
public VersionRange(@Nonnull Version aFloorVersion, boolean bIncludeFloorVersion, @Nullable Version aCeilingVersion, boolean bIncludeCeilingVersion) Create a new version range depicted by two versions.- Parameters:
aFloorVersion- the floor version of the range - may not be nullbIncludeFloorVersion- if true, a >= comparison is used on the version number, else a > comparison is usedaCeilingVersion- the ceiling version of the range - may be nullbIncludeCeilingVersion- if true, a <= comparison is used on the version number, else a < comparison is used- Throws:
IllegalArgumentException- if the floor version to be used is > the ceiling version or if the floor version is null.
-
-
Method Details
-
parse
Construct a version range object from a string.
Examples:
- [1.2.3, 4.5.6) -- 1.2.3 <= x < 4.5.6
- [1.2.3, 4.5.6] -- 1.2.3 <= x <= 4.5.6
- (1.2.3, 4.5.6) -- 1.2.3 < x < 4.5.6
- (1.2.3, 4.5.6] -- 1.2.3 < x <= 4.5.6
- 1.2.3 -- 1.2.3 <= x
- [1.2.3 -- 1.2.3 <= x
- (1.2.3 -- 1.2.3 < x
- null -- 0.0.0 <= x
- 1, 4 -- 1 <= x <= 4
- Parameters:
sVersionString- the version range in a string format as depicted above- Returns:
- The parsed
VersionRangeobject - Throws:
IllegalArgumentException- if the floor version is < than the ceiling version
-
isIncludingFloor
public boolean isIncludingFloor() -
getFloorVersion
-
isIncludingCeil
public boolean isIncludingCeil() -
getCeilVersion
-
versionMatches
-
compareTo
Compare this version range to another version range. Returns -1 if this is < than the passed version or +1 if this is > the passed version range- Specified by:
compareToin interfaceComparable<VersionRange>- Parameters:
rhs- the version range to compare to- Returns:
- 0 if the passed version range is equal to this version range
-1 if the floor version of this is < than the floor version of the passed version range.
-1 if the floor versions are equal but the ceiling version of this has a lower upper bound than the passed version range
+1 if the floor version of this is > than the floor version of the passed version range.
+1 if the floor versions are equal but the ceiling version of this has a higher upper bound than the passed version range
-
getAsString
Converts the version range to a string. The brackets whether floor or ceiling version should be included or not is always prepended and appended. If a ceiling version is present, the ceiling version is appended with a single comma as a delimiter.
Example return: "[1.2.3,4.5.6)"- Returns:
- The version range in a parseable string format.
-
getAsString
Converts the version range to a string. The brackets whether floor or ceiling version should be included or not is always prepended and appended. If a ceiling version is present, the ceiling version is appended with a single comma as a delimiter.
Example return: "[1.2.3,4.5.6)"- Parameters:
bPrintZeroElements- Iftruethan trailing zeroes are printed, otherwise printed zeroes are not printed.- Returns:
- Never
null.
-
equals
-
hashCode
public int hashCode() -
toString
-