Package org.instancio.generators
Class EnumGenerator
- java.lang.Object
-
- org.instancio.generators.AbstractRandomGenerator<Enum<?>>
-
- org.instancio.generators.EnumGenerator
-
- All Implemented Interfaces:
Generator<Enum<?>>
,GeneratorSpec<Enum<?>>
public class EnumGenerator extends AbstractRandomGenerator<Enum<?>>
-
-
Constructor Summary
Constructors Constructor Description EnumGenerator(GeneratorContext context, Class<?> enumClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Enum<?>
generate()
Depending on implementation, repeated invocations may return different values.-
Methods inherited from class org.instancio.generators.AbstractRandomGenerator
getContext, random
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.instancio.Generator
getHints, isDelegating, setDelegate, targetType
-
-
-
-
Constructor Detail
-
EnumGenerator
public EnumGenerator(GeneratorContext context, Class<?> enumClass)
-
-
Method Detail
-
generate
public Enum<?> generate()
Description copied from interface:Generator
Depending on implementation, repeated invocations may return different values. Some implementations may return random values on each invocation, while others may return predefined values or random values from a given set.Generators can be passed in as a lambda function. The following example shows how to override generation strategy for certain fields.
Person person = Instancio.of(Person.class) .generate(field("age"), gen -> gen.oneOf(20, 30, 40, 50)) .supply(field("location"), () -> "Canada") .supply(all(LocalDateTime.class), () -> LocalDateTime.now()) .create();
- Returns:
- generated value
-
-