Class ArrayGenerator<T>

java.lang.Object
org.instancio.internal.generator.AbstractGenerator<T>
org.instancio.internal.generator.array.ArrayGenerator<T>
All Implemented Interfaces:
Generator<T>, GeneratorSpec<T>, ArrayGeneratorSpec<T>

public class ArrayGenerator<T> extends AbstractGenerator<T> implements ArrayGeneratorSpec<T>
  • Field Details

    • minLength

      protected int minLength
    • maxLength

      protected int maxLength
  • Constructor Details

  • Method Details

    • minLength

      public ArrayGeneratorSpec<T> minLength(int length)
      Description copied from interface: ArrayGeneratorSpec
      Minimum length of array to generate.
      Specified by:
      minLength in interface ArrayGeneratorSpec<T>
      Parameters:
      length - minimum length (inclusive)
      Returns:
      spec builder
    • maxLength

      public ArrayGeneratorSpec<T> maxLength(int length)
      Description copied from interface: ArrayGeneratorSpec
      Maximum length of array to generate.
      Specified by:
      maxLength in interface ArrayGeneratorSpec<T>
      Parameters:
      length - maximum length (inclusive)
      Returns:
      spec builder
    • length

      public ArrayGeneratorSpec<T> length(int length)
      Description copied from interface: ArrayGeneratorSpec
      length of array to generate.
      Specified by:
      length in interface ArrayGeneratorSpec<T>
      Parameters:
      length - of array
      Returns:
      spec builder
    • nullable

      public ArrayGeneratorSpec<T> nullable()
      Description copied from interface: ArrayGeneratorSpec
      Indicates that null value can be generated for the array.
      Specified by:
      nullable in interface ArrayGeneratorSpec<T>
      Returns:
      spec builder
    • nullableElements

      public ArrayGeneratorSpec<T> nullableElements()
      Description copied from interface: ArrayGeneratorSpec
      Indicates that null values can be generated for array elements.
      Specified by:
      nullableElements in interface ArrayGeneratorSpec<T>
      Returns:
      spec builder
    • subtype

      public ArrayGenerator<T> subtype(Class<?> type)
      Description copied from interface: ArrayGeneratorSpec
      Specifies the type of array that should be generated.
      Specified by:
      subtype in interface ArrayGeneratorSpec<T>
      Parameters:
      type - of array to generate
      Returns:
      spec builder
    • with

      @SafeVarargs public final ArrayGeneratorSpec<T> with(T... elements)
      Description copied from interface: ArrayGeneratorSpec
      Adds given elements to the generated array at random positions.
      Specified by:
      with in interface ArrayGeneratorSpec<T>
      Parameters:
      elements - to add
      Returns:
      spec builder
    • generate

      public T 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<T>
      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<T>
      Overrides:
      hints in class AbstractGenerator<T>
      Returns:
      hints from this generator to the engine
      See Also: