Class VersionRange
- java.lang.Object
-
- org.apache.maven.artifact.versioning.VersionRange
-
public class VersionRange extends java.lang.ObjectConstruct a version range from a specification.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,VersionRange>CACHE_SPECprivate static java.util.Map<java.lang.String,VersionRange>CACHE_VERSIONprivate ArtifactVersionrecommendedVersionprivate java.util.List<Restriction>restrictions
-
Constructor Summary
Constructors Modifier Constructor Description privateVersionRange(ArtifactVersion recommendedVersion, java.util.List<Restriction> restrictions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description VersionRangecloneOf()Deprecated.VersionRange is immutable, cloning is not useful and even more an issue against the cachebooleancontainsVersion(ArtifactVersion version)static VersionRangecreateFromVersion(java.lang.String version)static VersionRangecreateFromVersionSpec(java.lang.String spec)Create a version range from a string representationbooleanequals(java.lang.Object obj)ArtifactVersiongetRecommendedVersion()java.util.List<Restriction>getRestrictions()ArtifactVersiongetSelectedVersion(Artifact artifact)inthashCode()booleanhasRestrictions()private java.util.List<Restriction>intersection(java.util.List<Restriction> r1, java.util.List<Restriction> r2)booleanisSelectedVersionKnown(Artifact artifact)ArtifactVersionmatchVersion(java.util.List<ArtifactVersion> versions)private static RestrictionparseRestriction(java.lang.String spec)VersionRangerestrict(VersionRange restriction)Creates and returns a newVersionRangethat is a restriction of this version range and the specified version range.java.lang.StringtoString()
-
-
-
Field Detail
-
CACHE_SPEC
private static final java.util.Map<java.lang.String,VersionRange> CACHE_SPEC
-
CACHE_VERSION
private static final java.util.Map<java.lang.String,VersionRange> CACHE_VERSION
-
recommendedVersion
private final ArtifactVersion recommendedVersion
-
restrictions
private final java.util.List<Restriction> restrictions
-
-
Constructor Detail
-
VersionRange
private VersionRange(ArtifactVersion recommendedVersion, java.util.List<Restriction> restrictions)
-
-
Method Detail
-
getRecommendedVersion
public ArtifactVersion getRecommendedVersion()
-
getRestrictions
public java.util.List<Restriction> getRestrictions()
-
cloneOf
@Deprecated public VersionRange cloneOf()
Deprecated.VersionRange is immutable, cloning is not useful and even more an issue against the cache- Returns:
- a clone
-
createFromVersionSpec
public static VersionRange createFromVersionSpec(java.lang.String spec) throws InvalidVersionSpecificationException
Create a version range from a string representation
Some spec examples are:1.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
-
parseRestriction
private static Restriction parseRestriction(java.lang.String spec) throws InvalidVersionSpecificationException
-
createFromVersion
public static VersionRange createFromVersion(java.lang.String version)
-
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:
java.lang.NullPointerException- if the specifiedVersionRangeisnull.
-
intersection
private java.util.List<Restriction> intersection(java.util.List<Restriction> r1, java.util.List<Restriction> r2)
-
getSelectedVersion
public ArtifactVersion getSelectedVersion(Artifact artifact) throws OverConstrainedVersionException
- Throws:
OverConstrainedVersionException
-
isSelectedVersionKnown
public boolean isSelectedVersionKnown(Artifact artifact) throws OverConstrainedVersionException
- Throws:
OverConstrainedVersionException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
matchVersion
public ArtifactVersion matchVersion(java.util.List<ArtifactVersion> versions)
-
containsVersion
public boolean containsVersion(ArtifactVersion version)
-
hasRestrictions
public boolean hasRestrictions()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-