package io.generators.core;

import com.google.common.collect.Range;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Range.closed;

/**
 * Generates random closed range of Comparable%lt;T%gt;
 *
 * @author Tomas Klubal
 */
public class RandomClosedRangeGenerator<T extends Comparable<T>> implements Generator<Range<T>> {
    private final Generator<T> delegate;

    /**
     * Creates range generator that delegates generation endpoints to its delegate
     *
     * @param delegate actual generator that generates values
     * @throws NullPointerException when <code>delegate</code> is null
     */
    public RandomClosedRangeGenerator(@Nonnull Generator<T> delegate) {
        this.delegate = checkNotNull(delegate, "Delegate generator can't be null");
    }

    @Override
    public Range<T> next() {
        T lower = delegate.next();
        T maybeUpper = delegate.next();
        T upper = lower.compareTo(maybeUpper) < 0 ? maybeUpper : lower;

        lower = upper == maybeUpper ? lower : maybeUpper;
        return closed(lower, upper);
    }
}

@@ -18,24 +18,67 @@
 tors.core;%0A%0A
+import com.google.common.collect.Ordering;%0A
 import com.g
@@ -946,21 +946,17 @@
       T 
-lower
+a
  = deleg
@@ -977,26 +977,17 @@
       T 
-maybeUpper
+b
  = deleg
@@ -1012,70 +1012,45 @@
   T 
-upp
+low
 er = 
-lower.compareTo(maybeUpper) %3C 0 ? maybeUpper : lower;%0A
+Ordering.natural().min(a, b);
 %0A   
@@ -1058,23 +1058,17 @@
     
-lower =
+T
  upper =
 = ma
@@ -1067,42 +1067,39 @@
 er =
-= maybeUpper ? lower : maybeUpper;
+ Ordering.natural().max(a, b);%0A
 %0A   

Replace confusing min/max selection logic