union method
Returns a PackageVersionNumberGeneralLibraryConstraint that allows PackageVersionNumberGeneralLibrarys allowed by either
this or other
.
Implementation
@override
PackageVersionNumberGeneralLibraryConstraint union(
PackageVersionNumberGeneralLibraryConstraint other) {
if (other is PackageVersionNumberGeneralLibrary) {
if (allows(other)) return this;
if (other == min) {
return PackageVersionNumberGeneralLibraryRange(
min: min,
max: max,
includeMin: true,
includeMax: includeMax,
alwaysIncludeMaxPreRelease: true);
}
if (other == max) {
return PackageVersionNumberGeneralLibraryRange(
min: min,
max: max,
includeMin: includeMin,
includeMax: true,
alwaysIncludeMaxPreRelease: true);
}
return PackageVersionNumberGeneralLibraryConstraint.unionOf(
[this, other]);
}
if (other is PackageVersionNumberGeneralLibraryRange) {
// If the two ranges don't overlap, we won't be able to create a single
// PackageVersionNumberGeneralLibraryRange for both of them.
var edgesTouch = (max != null &&
max == other.min &&
(includeMax || other.includeMin)) ||
(min != null && min == other.max && (includeMin || other.includeMax));
if (!edgesTouch && !allowsAny(other)) {
return PackageVersionNumberGeneralLibraryConstraint.unionOf(
[this, other]);
}
PackageVersionNumberGeneralLibrary? unionMin;
bool unionIncludeMin;
if (allowsLower(this, other)) {
unionMin = min;
unionIncludeMin = includeMin;
} else {
unionMin = other.min;
unionIncludeMin = other.includeMin;
}
PackageVersionNumberGeneralLibrary? unionMax;
bool unionIncludeMax;
if (allowsHigher(this, other)) {
unionMax = max;
unionIncludeMax = includeMax;
} else {
unionMax = other.max;
unionIncludeMax = other.includeMax;
}
return PackageVersionNumberGeneralLibraryRange(
min: unionMin,
max: unionMax,
includeMin: unionIncludeMin,
includeMax: unionIncludeMax,
alwaysIncludeMaxPreRelease: true);
}
return PackageVersionNumberGeneralLibraryConstraint.unionOf([this, other]);
}