Class ArrayGenerator<T>

java.lang.Object
org.instancio.generator.AbstractGenerator<T>
org.instancio.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
    • targetClass

      public Optional<Class<?>> targetClass()
      Description copied from interface: Generator
      Target class to generate.

      If Optional.empty() is returned, it will default to the field type for fields, and element type for collection and array elements.

      If the type is an interface, such as Set, will generate a default implementation class such as HashSet.

      Specified by:
      targetClass in interface Generator<T>
      Returns:
      target class
    • generate

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

      If the generated value is random, it needs to be generated using the given Random instance. This ensures the data is generated with the same seed value and allows random data to be reproduced by specifying the seed value.

      Specified by:
      generate in interface Generator<T>
      Parameters:
      random - provider for generating random values
      Returns:
      generated value
    • getHints

      public GeneratedHints getHints()
      Description copied from interface: Generator
      Returns hints, including collection sizes and whether values are nullable.
      Specified by:
      getHints in interface Generator<T>
      Returns:
      generated hints