code: public static <E extends Comparable<E>> Interval<E> toInterval(E a, E b, int flags) {
      int comp = a.compareTo(b);
      if (comp <= 0) {
        return new Interval(a,b, flags);
      } else {
        return null;
      }
    }
docs: Create an interval with the specified endpoints in the specified order,
  using the specified flags.  Returns null if a does not come before b
  (invalid interval)
  @param a start endpoints
  @param b end endpoint
  @param flags flags characterizing the interval
  @param <E> type of the interval endpoints
  @return Interval with endpoints in specified order, null if a does not come before b