Intervals union(Intervals that) {
      if (this.isEmpty()) {
        return that;
      } else if (that.isEmpty()) {
        return this;
      }
      Intervals result = new Intervals();

      int thisSize = this.getIntervalSize();
      int thatSize = that.getIntervalSize();
      int thisIndex = 0;
      int thatIndex = 0;
      // merge the heads of the two intervals
      while (thisIndex < thisSize && thatIndex < thatSize) {
        long thisLB = this.getLowerBound(thisIndex);
        long thisUB = this.getUpperBound(thisIndex);
        long thatLB = that.getLowerBound(thatIndex);
        long thatUB = that.getUpperBound(thatIndex);
        if (thisLB <= thatLB) {
          result.mergeLast(thisLB, thisUB);
          thisIndex++;
        } else {
          result.mergeLast(thatLB, thatUB);
          thatIndex++;
        }
      }
      // merge the remaining intervals
      Intervals remainingIntervals = thisIndex < thisSize ? this : that;
      int remainingIndex = thisIndex < thisSize ? thisIndex : thatIndex;
      mergeRemainingIntervals(remainingIndex, remainingIntervals, result);

      return result;
    }
The union is implemented by merge, so the two intervals must be ordered.

@param that
@return
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/TimeValuePairUtils.java