join method

Interval join(
  1. Interval other
)

Implementation

Interval join(Interval other) {
  if (this.overlaps(other) || this.adjacentTo(other)) {
    int lbound;
    bool linc;
    if (this.lowerBound < other.lowerBound) {
      lbound = this.lowerBound;
      linc = this.lowerClosed;
    } else if (this.lowerBound == other.lowerBound) {
      lbound = this.lowerBound;
      linc = this.lowerClosed || other.lowerClosed;
    } else {
      lbound = other.lowerBound;
      linc = other.lowerClosed;
    }
    int ubound;
    bool uinc;
    if (this.upperBound > other.upperBound) {
      ubound = this.upperBound;
      uinc = this.upperClosed;
    } else if (this.upperBound == other.upperBound) {
      ubound = this.upperBound;
      uinc = this.upperClosed || other.upperClosed;
    } else {
      ubound = other.upperBound;
      uinc = other.upperClosed;
    }
    return Interval._(lbound, ubound, upperClosed: uinc, lowerClosed: linc);
  } else {
    throw Exception("The Intervals are disjoint.");
  }
}