Package org.instancio

Interface Generator<T>

    • Method Detail

      • generate

        T generate​(RandomProvider random)
        Returns a generated value.

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

        Parameters:
        random - provider for random values
        Returns:
        generated value
      • isDelegating

        default boolean isDelegating()
        If true, then this generator delegate object instantiation to another generator supplied via setDelegate(Generator).

        A generator is delegating when it does not know the type it needs to generate. For example, the collection generator could generate an ArrayList, a HashSet, or some other collection type.

        Returns:
        true if this is a delegating generator
      • setDelegate

        default void setDelegate​(Generator<?> delegate)
        Set a delegate that will be responsible for instantiating an object on behalf of this generator.
        Parameters:
        delegate - that will create the target object
      • apiMethodName

        default Optional<String> apiMethodName()
        Returns the public API method name of this generator. Will return an empty result if this instance is a lambda.
        Returns:
        spec name, if defined
      • targetClass

        default Optional<Class<?>> targetClass()
        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.

        Returns:
        target class
      • supports

        default boolean supports​(Class<?> type)
        Checks whether this generator can generate given type.
        Parameters:
        type - to check
        Returns:
        true if generator can
      • getHints

        default GeneratedHints getHints()
        Returns hints, including collection sizes and whether values are nullable.
        Returns:
        generated hints