Package org.instancio
Interface Generator<T>
-
- Type Parameters:
T
- type to generate
- All Superinterfaces:
GeneratorSpec<T>
- All Known Implementing Classes:
AbstractGenerator
,AbstractRandomComparableNumberGeneratorSpec
,AbstractRandomNumberGeneratorSpec
,ArrayGenerator
,AtomicIntegerGenerator
,AtomicLongGenerator
,BigDecimalGenerator
,BigIntegerGenerator
,BooleanGenerator
,ByteGenerator
,CalendarGenerator
,CharacterGenerator
,CollectionGenerator
,CollectionGeneratorSpecImpl
,ConcurrentHashMapGenerator
,ConcurrentSkipListMapGenerator
,DateGenerator
,DoubleGenerator
,EnumGenerator
,EnumSetGenerator
,FloatGenerator
,HashSetGenerator
,InstantGenerator
,InstantiatingGenerator
,IntegerGenerator
,LocalDateGenerator
,LocalDateTimeGenerator
,LocalTimeGenerator
,LongGenerator
,MapGenerator
,MapGeneratorSpecImpl
,OneOfArrayGenerator
,OneOfCollectionGenerator
,ShortGenerator
,SqlDateGenerator
,StringBuilderGenerator
,StringGenerator
,TextPatternGenerator
,TimestampGenerator
,TreeMapGenerator
,TreeSetGenerator
,UUIDGenerator
,XMLGregorianCalendarGenerator
,YearGenerator
,YearMonthGenerator
,ZonedDateTimeGenerator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Generator<T> extends GeneratorSpec<T>
A generator of values of a specific type.- Since:
- 1.0.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Optional<String>
apiMethodName()
Returns the public API method name of this generator.T
generate(Random random)
Returns a generated value.default GeneratedHints
getHints()
Returns hints, including collection sizes and whether values are nullable.default boolean
isDelegating()
Iftrue
, then this generator delegate object instantiation to another generator supplied viasetDelegate(Generator)
.default void
setDelegate(Generator<?> delegate)
Set a delegate that will be responsible for instantiating an object on behalf of this generator.default boolean
supports(Class<?> type)
Checks whether this generator can generate given type.default Optional<Class<?>>
targetClass()
Target class to generate.
-
-
-
Method Detail
-
generate
T generate(Random random)
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.- Parameters:
random
- provider for random values- Returns:
- generated value
-
isDelegating
default boolean isDelegating()
Iftrue
, then this generator delegate object instantiation to another generator supplied viasetDelegate(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
, aHashSet
, 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 asHashSet
.- 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
-
-