code: public static <E extends Comparable<E>> Interval<E> toValidInterval(E a, E b, int flags) {
      int comp = a.compareTo(b);
      if (comp <= 0) {
        return new Interval(a,b,flags);
      } else {
        return new Interval(b,a,flags);
      }
    }
docs: Create an interval with the specified endpoints, reordering them as needed,
  using the specified flags
  @param a one of the endpoints
  @param b the other endpoint
  @param flags flags characterizing the interval
  @param <E> type of the interval endpoints
  @return Interval with endpoints re-ordered as needed