Class EnumGenerator<E extends Enum<E>>

java.lang.Object
org.instancio.internal.generator.lang.EnumGenerator<E>
All Implemented Interfaces:
AsStringGeneratorSpec<E>, Generator<E>, GeneratorSpec<E>, EnumGeneratorSpec<E>

public class EnumGenerator<E extends Enum<E>> extends Object implements EnumGeneratorSpec<E>, Generator<E>
  • Constructor Details

    • EnumGenerator

      public EnumGenerator(Class<E> enumClass)
  • Method Details

    • excluding

      @SafeVarargs public final EnumGeneratorSpec<E> excluding(E... values)
      Description copied from interface: EnumGeneratorSpec
      Generate an enum while excluding the specified values. The argument can be an empty array, but not null.
      Specified by:
      excluding in interface EnumGeneratorSpec<E extends Enum<E>>
      Parameters:
      values - to exclude
      Returns:
      spec builder
    • nullable

      public EnumGeneratorSpec<E> nullable()
      Description copied from interface: EnumGeneratorSpec
      Indicates that null value can be generated.
      Specified by:
      nullable in interface EnumGeneratorSpec<E extends Enum<E>>
      Returns:
      spec builder
    • generate

      public E generate(Random random)
      Description copied from interface: Generator
      Returns a generated value.

      If this method produces random data, the data needs to be generated using the provided Random instance. This ensures generated values are reproducible for a given seed value.

      Specified by:
      generate in interface Generator<E extends Enum<E>>
      Parameters:
      random - provider for generating random values
      Returns:
      generated value or null if value is nullable, could not be generated, or generation is delegated to the engine
    • hints

      public Hints hints()
      Description copied from interface: Generator
      Hints provided by the generator to the engine.

      The most important hint for custom generators is AfterGenerate. This hint indicates whether the object created by this generator:

      • should be populated (for example, if it has null fields)
      • can be modified using selectors

      For example, setting the hint to AfterGenerate.POPULATE_NULLS will cause Instancio to populate null fields on the object returned by this generator:

      
         @Override
         public Hints hints() {
             return Hints.afterGenerate(AfterGenerate.POPULATE_NULLS);
         }
       

      If the action is not specified, default behaviour will be based on the AfterGenerate value configured in the Settings using the key Keys.AFTER_GENERATE_HINT.

      In addition, the following hints can be provided for populating data structures:

      Specified by:
      hints in interface Generator<E extends Enum<E>>
      Returns:
      hints from this generator to the engine
      See Also: