Class VersionRange
- java.lang.Object
-
- org.hotswap.agent.versions.VersionRange
-
public class VersionRange extends Object
Construct a version range from a specification.- Author:
- Brett Porter
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static VersionRangeany()Any.VersionRangecloneOf()Clone of.booleancontainsVersion(ArtifactVersion version)Contains version.static VersionRangecreateFromVersion(String version)Creates the from version.static VersionRangecreateFromVersionSpec(String spec)Create a version range from a string representationbooleanequals(Object obj)ArtifactVersiongetRecommendedVersion()Gets the recommended version.List<Restriction>getRestrictions()Gets the restrictions.ArtifactVersiongetSelectedVersion()Gets the selected version.inthashCode()booleanhasRestrictions()Checks for restrictions.booleanisSelectedVersionKnown()Checks if is selected version known.ArtifactVersionmatchVersion(List<ArtifactVersion> versions)Match version.VersionRangerestrict(VersionRange restriction)Creates and returns a newVersionRangethat is a restriction of this version range and the specified version range.StringtoString()
-
-
-
Method Detail
-
getRecommendedVersion
public ArtifactVersion getRecommendedVersion()
Gets the recommended version.- Returns:
- the recommended version
-
getRestrictions
public List<Restriction> getRestrictions()
Gets the restrictions.- Returns:
- the restrictions
-
cloneOf
public VersionRange cloneOf()
Clone of.- Returns:
- the version range
-
any
public static VersionRange any()
Any.- Returns:
- the version range
-
createFromVersionSpec
public static VersionRange createFromVersionSpec(String spec) throws InvalidVersionSpecificationException
Create a version range from a string representation Some spec examples are1.0Version 1.0[1.0,2.0)Versions 1.0 (included) to 2.0 (not included)[1.0,2.0]Versions 1.0 to 2.0 (both included)[1.5,)Versions 1.5 and higher(,1.0],[1.2,)Versions up to 1.0 (included) and 1.2 or higher
- Parameters:
spec- string representation of a version or version range- Returns:
- a new
VersionRangeobject that represents the spec - Throws:
InvalidVersionSpecificationException- the invalid version specification exception
-
createFromVersion
public static VersionRange createFromVersion(String version)
Creates the from version.- Parameters:
version- the version- Returns:
- the version range
-
restrict
public VersionRange restrict(VersionRange restriction)
Creates and returns a newVersionRangethat is a restriction of this version range and the specified version range.Note: Precedence is given to the recommended version from this version range over the recommended version from the specified version range.
- Parameters:
restriction- theVersionRangethat will be used to restrict this version range.- Returns:
- the
VersionRangethat is a restriction of this version range and the specified version range.The restrictions of the returned version range will be an intersection of the restrictions of this version range and the specified version range if both version ranges have restrictions. Otherwise, the restrictions on the returned range will be empty.
The recommended version of the returned version range will be the recommended version of this version range, provided that ranges falls within the intersected restrictions. If the restrictions are empty, this version range's recommended version is used if it is not
null. If it isnull, the specified version range's recommended version is used (provided it is non-null). If no recommended version can be obtained, the returned version range's recommended version is set tonull. - Throws:
NullPointerException- if the specifiedVersionRangeisnull.
-
getSelectedVersion
public ArtifactVersion getSelectedVersion()
Gets the selected version.- Returns:
- the selected version
-
isSelectedVersionKnown
public boolean isSelectedVersionKnown()
Checks if is selected version known.- Returns:
- true, if is selected version known
-
matchVersion
public ArtifactVersion matchVersion(List<ArtifactVersion> versions)
Match version.- Parameters:
versions- the versions- Returns:
- the artifact version
-
containsVersion
public boolean containsVersion(ArtifactVersion version)
Contains version.- Parameters:
version- the version- Returns:
- true, if successful
-
hasRestrictions
public boolean hasRestrictions()
Checks for restrictions.- Returns:
- true, if successful
-
-