Package com.helger.commons.version
Class VersionRange
- java.lang.Object
-
- com.helger.commons.version.VersionRange
-
- All Implemented Interfaces:
IComparable<VersionRange>,Comparable<VersionRange>
@Immutable public final class VersionRange extends Object implements IComparable<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 Modifier and Type Field Description static StringDEFAULT_VERSION_RANGE_STRINGDefault version range string.
-
Constructor Summary
Constructors Constructor Description VersionRange(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(VersionRange rhs)Compare this version range to another version range.booleanequals(Object o)StringgetAsString()Converts the version range to a string.StringgetAsString(boolean bPrintZeroElements)Converts the version range to a string.VersiongetCeilVersion()VersiongetFloorVersion()inthashCode()booleanisIncludingCeil()booleanisIncludingFloor()static VersionRangeparse(String sVersionString)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 <= 4StringtoString()booleanversionMatches(Version rhs)
-
-
-
Field Detail
-
DEFAULT_VERSION_RANGE_STRING
public static final String DEFAULT_VERSION_RANGE_STRING
Default version range string.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VersionRange
public VersionRange(@Nonnull Version aFloorVersion, @Nullable 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.- 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 Detail
-
parse
@Nonnull public static VersionRange parse(@Nullable String sVersionString)
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()
-
isIncludingCeil
public boolean isIncludingCeil()
-
compareTo
public int compareTo(@Nonnull VersionRange rhs)
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
@Nonnull public String 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
@Nonnull public String getAsString(boolean bPrintZeroElements)
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.
-
-