public static <E extends Enum<E>> EnumSet<E> range(E from, E to) {
        if (from.compareTo(to) > 0)
            throw new IllegalArgumentException(from + " > " + to);
        EnumSet<E> result = noneOf(from.getDeclaringClass());
        result.addRange(from, to);
        return result;
    }
public static < E extends Enum < E > > EnumSet < E > range ( E from , E to ) { if ( from . compareTo ( to ) > 0 ) throw new IllegalArgumentException ( from + " > " + to ) ; EnumSet < E > result = noneOf ( from . getDeclaringClass ( ) ) ; result . addRange ( from , to ) ; return result ; }
Creates an enum set initially containing all of the elements in the
range defined by the two specified endpoints.  The returned set will
contain the endpoints themselves, which may be identical but must not
be out of order.

@param <E> The class of the parameter elements and of the set
@param from the first element in the range
@param to the last element in the range
@throws NullPointerException if {@code from} or {@code to} are null
@throws IllegalArgumentException if {@code from.compareTo(to) > 0}
@return an enum set initially containing all of the elements in the
range defined by the two specified endpoints