Package org.cthing.versionparser
Class VersionConstraint
java.lang.Object
org.cthing.versionparser.VersionConstraint
Represents zero (empty constraint) or more version ranges. A version range is a contiguous set of versions
(e.g. version 1.0 inclusive through version 2.0 exclusive). Constraints can be weak or strong (the default).
A weak constraint is one that can be ignored by a dependency resolution algorithm if necessary (e.g. Maven
undecorated versions). Typically, an instance of this class is created by using a versioning scheme class
to parse a version constraint string. The notation for version constraints is specific to a version scheme
(e.g. Maven). Please refer to the Javadoc for the specific version scheme classes for information about the
notation and the method to call to create an instance of this class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VersionConstraintConstraint allowing any version.static final VersionConstraintConstraint not allowing any version. -
Constructor Summary
ConstructorsConstructorDescriptionVersionConstraint(@Nullable Version minVersion, @Nullable Version maxVersion, boolean minIncluded, boolean maxIncluded) Constructs a strong version range from the specified minimum and maximum versions.VersionConstraint(@Nullable Version minVersion, @Nullable Version maxVersion, boolean minIncluded, boolean maxIncluded, boolean weak) Constructs a version range from the specified minimum and maximum versions.VersionConstraint(List<VersionRange> ranges) Constructs a strong constraint consisting of the union of version ranges.VersionConstraint(List<VersionRange> ranges, boolean weak) Constructs a constraint consisting of the union of version ranges.VersionConstraint(Version version) Constructs a strong version constraint consisting of a single version (i.e.VersionConstraint(Version version, boolean weak) Constructs a version constraint consisting of a single version (i.e. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates if the specified version is allowed by this constraint.booleanallowsAll(VersionConstraint other) Indicates if this constraint allows all versions that are allowed by the specified constraint.booleanallowsAny(VersionConstraint other) Indicates if this constraint allows any of the versions allowed by the specified constraint.Creates a constraint that is the complement of this constraint.difference(VersionConstraint other) Creates a constraint that allows versions allowed by this constraint but not by the specified constraint.booleanObtains the version ranges comprising this constraint.inthashCode()intersect(VersionConstraint other) Creates a constraint that only allows versions allowed by both this and the specified constraints.booleanisAny()Indicates whether this constraint allows all versions.booleanisEmpty()Indicates whether this constraint does not contain any versions.booleanIndicates whether this constraint contains any versions.booleanIndicates whether this constraint represents a single version (e.g.booleanisWeak()Indicates whether this constraint can be ignored by a dependency resolution algorithm.toString()union(VersionConstraint other) Creates a constraint that allows versions allowed by either this or the specified constraint.
-
Field Details
-
ANY
Constraint allowing any version. -
EMPTY
Constraint not allowing any version.
-
-
Constructor Details
-
VersionConstraint
Constructs a strong version constraint consisting of a single version (i.e. the minimum version equals the maximum version inclusive at both ends).- Parameters:
version- Single version comprising the range
-
VersionConstraint
Constructs a version constraint consisting of a single version (i.e. the minimum version equals the maximum version inclusive at both ends).- Parameters:
version- Single version comprising the rangeweak-trueif this constraint can be ignored by dependency resolution algorithms
-
VersionConstraint
public VersionConstraint(@Nullable Version minVersion, @Nullable Version maxVersion, boolean minIncluded, boolean maxIncluded) Constructs a strong version range from the specified minimum and maximum versions.- Parameters:
minVersion- Version defining the lower bound of the range. Specifynullif there is no lower bound.maxVersion- Version defining the upper bound of the range Specifynullif there is no upper bound.minIncluded-trueif the minimum version is included in the range. If the minimum version isnull, this parameter must be set tofalse.maxIncluded-trueif the maximum version is included in the range. If the maximum version isnull, this parameter must be set tofalse.
-
VersionConstraint
public VersionConstraint(@Nullable Version minVersion, @Nullable Version maxVersion, boolean minIncluded, boolean maxIncluded, boolean weak) Constructs a version range from the specified minimum and maximum versions.- Parameters:
minVersion- Version defining the lower bound of the range. Specifynullif there is no lower bound.maxVersion- Version defining the upper bound of the range Specifynullif there is no upper bound.minIncluded-trueif the minimum version is included in the range. If the minimum version isnull, this parameter must be set tofalse.maxIncluded-trueif the maximum version is included in the range. If the maximum version isnull, this parameter must be set tofalse.weak-trueif this constraint can be ignored by dependency resolution algorithms
-
VersionConstraint
Constructs a strong constraint consisting of the union of version ranges.- Parameters:
ranges- Version ranges that comprise this union
-
VersionConstraint
Constructs a constraint consisting of the union of version ranges.- Parameters:
ranges- Version ranges that comprise this unionweak-trueif this constraint can be ignored by dependency resolution algorithms
-
-
Method Details
-
getRanges
Obtains the version ranges comprising this constraint.- Returns:
- Version ranges comprising this constraint. If the constraint is empty (i.e. contains no version ranges), an empty list is returned.
-
isEmpty
public boolean isEmpty()Indicates whether this constraint does not contain any versions.- Returns:
trueif this constraint does not contain any versions.
-
isNotEmpty
public boolean isNotEmpty()Indicates whether this constraint contains any versions.- Returns:
trueif this constraint contains at least one version.
-
isAny
public boolean isAny()Indicates whether this constraint allows all versions.- Returns:
trueif this constraint allows all versions.
-
isWeak
public boolean isWeak()Indicates whether this constraint can be ignored by a dependency resolution algorithm. For example, Maven treats an undecorated dependency version constraint (e.g.1.0.0) as "soft" (i.e. weak), meaning that during dependency mediation, the version can be replaced by a different version if necessary.- Returns:
trueif this is a weak constraint.
-
isSingleVersion
public boolean isSingleVersion()Indicates whether this constraint represents a single version (e.g. [4.0.0]).- Returns:
trueif this constraint represents a single version.
-
allows
Indicates if the specified version is allowed by this constraint.- Parameters:
version- Version to test- Returns:
trueif the specified version is allowed by this constraint.
-
allowsAll
Indicates if this constraint allows all versions that are allowed by the specified constraint.- Parameters:
other- Constraint defining the versions to be allowed by this constraint- Returns:
trueif this constraint allows all versions allowed by the specified constraint.
-
allowsAny
Indicates if this constraint allows any of the versions allowed by the specified constraint.- Parameters:
other- Constraint defining the versions any of which are allowed by this constraint- Returns:
trueif this constraint allows any of the versions allowed by the specified constraint.
-
intersect
Creates a constraint that only allows versions allowed by both this and the specified constraints. The following examples show the intersection of this constraint T and the specified constraint C:T = [] C = [] T ∩ C = [] T = [] C = (,) T ∩ C = [] T = [1.5] C = [] T ∩ C = [] T = [1.5,2.0] C = [1.7] T ∩ C = [1.7] T = [1.5,2.0] C = [1.6,1.9] T ∩ C = [1.6,1.9] T = [1.5,) C = [1.2,1.8] T ∩ C = [1.5,1.8] T = (,3.0) C = (,1.8] T ∩ C = (,1.8] T = [1.5,2.0) C = [1.6],[1.8] T ∩ C = [1.6],[1.8] T = [1.5,2.0),[3.0,4.0) C = [] T ∩ C = [] T = [1.5,2.0),[3.0,4.0) C = [1.6,1.6] T ∩ C = [1.6,1.6] T = [1.5,2.0),[3.0,4.0) C = [1.6,1.8] T ∩ C = [1.6,1.8] T = [1.5,2.0),[3.0,4.0) C = [1.6,1.8],[3.2,3.4] T ∩ C = [1.6,1.8],[3.2,3.4]
- Parameters:
other- Constraint to intersect with this constraint- Returns:
- A new constraint that only allows versions allowed by both this and the specified constraints. Returns an empty constraint if there is no intersection between this and the specified constraints.
-
union
Creates a constraint that allows versions allowed by either this or the specified constraint. The following examples show the union of this constraint T and the specified constraint C:T = [] C = [] T ∪ C = [] T = [] C= (,) T ∪ C = (,) T = [1.5] C = [] T ∪ C = [1.5] T = [1.5] C = [1.5] T ∪ C = [1.5] T = [1.5] C = [1.6] T ∪ C = [1.5],[1.6] T = [1.5,1.7) C = [1.6] T ∪ C = [1.5,1.7) T = (1.5,) C = [1.3,2.0] T ∪ C = [1.3,) T = (,1.7] C = [1.5,2.0] T ∪ C = (,2.0] T = (,) C = [1.5,2.0] T ∪ C = (,) T = [1.2,2.0) C = (,) T ∪ C = (,) T = (1.0,2.0) C = (2.0,3.0) T ∪ C = (1.0,2.0),(2.0,3.0) T = [1.5,2.0),[3.0,4.0) C = [1.6,1.6] T ∪ C = [1.5,2.0),[3.0,4.0)
- Parameters:
other- Constraint to for a union with this constraint- Returns:
- A new constraint that allows versions allowed by either this or the specified constraint.
-
difference
Creates a constraint that allows versions allowed by this constraint but not by the specified constraint. The following examples show the difference between this constraint T and the specified constraint C:T = [1.5] C = [] T - C = [1.5] T = [1.5] C = [1.5] T - C = [] T = [1.2,2.0) C = [1.5,1.5] T - C = [1.2,1.5),(1.5,2.0) T = [1.2,2.0) C = [1.2,1.2] T - C = (1.2,2.0) T = [1.2,2.0) C = (,) T - C = [] T = [1.2,2.0) C = [1.5,1.5],[1.7,1.7] T - C = [1.2,1.5),(1.5,1.7),(1.7,2.0) T = [1.5],[2.0,3.0) C = [] T - C = [1.5],[2.0,3.0) T = [1.5],[2.0,3.0) C = [1.5,1.5] T - C = [2.0,3.0) T = [1.0,3.0),(4.0,6.0) C = [2.0],[7.0,8.0) T - C = [1.0,2.0),(2.0,3.0),(4.0,6.0) T = [] C = [] T - C = [] T = [] C = [1.2,2.0) T - C = []
- Parameters:
other- Constraint to form the difference with this constraint- Returns:
- A new constraint that allows versions allowed by this constraint but not by the specified constraint.
-
complement
Creates a constraint that is the complement of this constraint. The following examples show the constraint C and its complement C':C = [] C' = (,) C = [1.5] C' = (,1.5),(1.5,) C = [1.2,2.0) C' = (,1.2),[2.0,) C = [1.5],[2.0,3.0) C' = (,1.5),(1.5,2.0),[3.0,) C = [1.5],[2.0,3.0),[4.0,7.0) C' = (,1.5),(1.5,2.0),[3.0,4.0),[7.0,)
- Returns:
- Complement of this constraint.
-
equals
-
hashCode
public int hashCode() -
toString
-