operator & method Null safety

Interval operator &(
  1. Interval other
)

Implementation

Interval operator &(Interval other) {
  Interval result;
  if (this == other) {
    result = Interval._(this.lowerBound, this.upperBound,
        lowerClosed: this.lowerClosed, upperClosed: this.upperClosed);
  } else if (this.comes_before(other)) {
    if (this.overlaps(other)) {
      int lower;
      bool lower_closed;
      if (this.lowerBound == other.lowerBound) {
        lower = this.lowerBound;
        lower_closed = this.lowerClosed && other.lowerClosed;
      } else if (this.lowerBound > other.lowerBound) {
        lower = this.lowerBound;
        lower_closed = this.lowerClosed;
      } else {
        lower = other.lowerBound;
        lower_closed = other.lowerClosed;
      }
      int upper;
      bool upper_closed;
      if (this.upperBound == other.upperBound) {
        upper = this.upperBound;
        upper_closed = this.upperClosed || other.upperClosed;
      } else if (this.upperBound < other.upperBound) {
        upper = this.upperBound;
        upper_closed = this.upperClosed;
      } else {
        upper = other.upperBound;
        upper_closed = other.upperClosed;
      }
      result = Interval._(lower, upper,
          lowerClosed: lower_closed, upperClosed: upper_closed);
    } else {
      result = Interval.none();
    }
  } else {
    result = other & this;
  }
  return result;
}