@Override
  public int compareTo(Interval<T> o) {
    int result = low.compareTo(o.low);
    if (result == 0) {
      if (isClosedOnLow != o.isClosedOnLow) {
        result = isClosedOnLow ? -1 : 1;
      } else {
        result = high.compareTo(o.high);
        if (result == 0) {
          if (isClosedOnHigh != o.isClosedOnHigh) {
            result = isClosedOnHigh ? -1 : 1;
          }
        }
      }
    }
    return result;
  }