union method

VersionConstraint union (VersionConstraint other)
override

Returns a VersionConstraint that allows Versionss allowed by either this or other.

Implementation

VersionConstraint union(VersionConstraint other) {
  if (other is Version) {
    if (allows(other)) return this;

    if (other == min) {
      return new VersionRange(
          min: this.min,
          max: this.max,
          includeMin: true,
          includeMax: this.includeMax,
          alwaysIncludeMaxPreRelease: true);
    }

    if (other == max) {
      return new VersionRange(
          min: this.min,
          max: this.max,
          includeMin: this.includeMin,
          includeMax: true,
          alwaysIncludeMaxPreRelease: true);
    }

    return new VersionConstraint.unionOf([this, other]);
  }

  if (other is VersionRange) {
    // If the two ranges don't overlap, we won't be able to create a single
    // VersionRange for both of them.
    var edgesTouch = (max == other.min && (includeMax || other.includeMin)) ||
        (min == other.max && (includeMin || other.includeMax));
    if (!edgesTouch && !allowsAny(other)) {
      return new VersionConstraint.unionOf([this, other]);
    }

    Version unionMin;
    bool unionIncludeMin;
    if (allowsLower(this, other)) {
      unionMin = this.min;
      unionIncludeMin = this.includeMin;
    } else {
      unionMin = other.min;
      unionIncludeMin = other.includeMin;
    }

    Version unionMax;
    bool unionIncludeMax;
    if (allowsHigher(this, other)) {
      unionMax = this.max;
      unionIncludeMax = this.includeMax;
    } else {
      unionMax = other.max;
      unionIncludeMax = other.includeMax;
    }

    return new VersionRange(
        min: unionMin,
        max: unionMax,
        includeMin: unionIncludeMin,
        includeMax: unionIncludeMax,
        alwaysIncludeMaxPreRelease: true);
  }

  return new VersionConstraint.unionOf([this, other]);
}