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
,CharacterGenerator
,CollectionGenerator
,CollectionGeneratorSpecImpl
,ConcurrentHashMapGenerator
,ConcurrentSkipListMapGenerator
,DateGenerator
,DoubleGenerator
,EnumGenerator
,EnumSetGenerator
,FloatGenerator
,HashSetGenerator
,InstantiatingGenerator
,IntegerGenerator
,LocalDateGenerator
,LocalDateTimeGenerator
,LongGenerator
,MapGenerator
,MapGeneratorSpecImpl
,OneOfArrayGenerator
,OneOfCollectionGenerator
,ShortGenerator
,StringGenerator
,TextPatternGenerator
,TreeMapGenerator
,TreeSetGenerator
,UUIDGenerator
,XMLGregorianCalendarGenerator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A generator of values of a specific type.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of this generator.generate
(RandomProvider random) Returns a generated value.default GeneratedHints
getHints()
Returns hints, including collection sizes and whether values are nullable.default boolean
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
Checks whether this generator can generate given type.Target class to generate.
-
Method Details
-
generate
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()Iftrue
, then this generator delegate object instantiation to another generator supplied viasetDelegate(Generator)
.- Returns:
true
if this is a delegating generator
-
setDelegate
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
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
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
Checks whether this generator can generate given type.- Parameters:
type
- to check- Returns:
true
if generator can
-
getHints
Returns hints, including collection sizes and whether values are nullable.- Returns:
- generated hints
-