package io.fotoapparat.parameter.range;

import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Class with factory and utility methods for {@link Range}.
 */
public class Ranges {

    public static <T extends Comparable<T>> Range<T> range(@NonNull T lowerBound,
                                                           @NonNull T upperBound) {
        return new ContinuousRange<>(lowerBound, upperBound);
    }

    public static <T extends Comparable<T>> Range<T> range(@NonNull T value) {
        return new ContinuousRange<>(value, value);
    }

    public static <T extends Comparable<T>> Range<T> discreteRange(@NonNull Collection<T> collection) {
        List<T> list = (collection instanceof List)
                ? (List<T>) collection
                : new ArrayList<>(collection);
        Collections.sort(list);
        return new DiscreteRange<>(list);
    }

    public static <T extends Comparable<T>> Range<T> emptyRange() {
        return new EmptyRange<>();
    }

    public static <T extends Comparable<T>> boolean isEmpty(@NonNull Range<T> range) {
        return range instanceof EmptyRange;
    }
}

@@ -99,99 +99,18 @@
 til.
-ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.List
+Collection
 ;%0A%0A/
@@ -681,178 +681,8 @@
 ) %7B%0A
-        List%3CT%3E list = (collection instanceof List)%0A                ? (List%3CT%3E) collection%0A                : new ArrayList%3C%3E(collection);%0A        Collections.sort(list);%0A
     
@@ -716,12 +716,18 @@
 e%3C%3E(
-list
+collection
 );%0A 

Remove redundant sort in Ranges