All Downloads are FREE. Search and download functionalities are using the official Maven repository.

smallcheck.generators.EnumGen Maven / Gradle / Ivy

The newest version!
package smallcheck.generators;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.stream.Stream;

/**
 *
 */
public class EnumGen> extends SeriesGen {

    private final T[] values;

    public EnumGen(T...values) {
        this.values = values;
    }

    public EnumGen(Class enumClass) {
        try {
            Method m = enumClass.getMethod("values");
            m.setAccessible(true);
            Object valuesObj = m.invoke(null);
            @SuppressWarnings("unchecked")
            T[] values = (T[]) valuesObj;
            this.values = values;
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Stream generate(int depth) {
        return Stream.of(values).limit(depth);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy