Package org.instancio.generator.util
Class CollectionGeneratorSpecImpl<T>
- java.lang.Object
-
- org.instancio.generator.AbstractGenerator<Collection<T>>
-
- org.instancio.generator.util.CollectionGenerator<T>
-
- org.instancio.generator.util.CollectionGeneratorSpecImpl<T>
-
- All Implemented Interfaces:
Generator<Collection<T>>
,GeneratorSpec<Collection<T>>
,CollectionGeneratorSpec<T>
public class CollectionGeneratorSpecImpl<T> extends CollectionGenerator<T>
-
-
Field Summary
-
Fields inherited from class org.instancio.generator.util.CollectionGenerator
maxSize, minSize, nullable, nullableElements, type, withElements
-
-
Constructor Summary
Constructors Constructor Description CollectionGeneratorSpecImpl(GeneratorContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<T>
generate(Random random)
Returns a generated value.boolean
isDelegating()
Iftrue
, then this generator delegate object instantiation to another generator supplied viaGenerator.setDelegate(Generator)
.void
setDelegate(Generator<?> delegate)
Set a delegate that will be responsible for instantiating an object on behalf of this generator.Optional<Class<?>>
targetClass()
Target class to generate.-
Methods inherited from class org.instancio.generator.util.CollectionGenerator
getHints, maxSize, minSize, nullable, nullableElements, size, type, with
-
Methods inherited from class org.instancio.generator.AbstractGenerator
getContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.instancio.Generator
apiMethodName, supports
-
-
-
-
Constructor Detail
-
CollectionGeneratorSpecImpl
public CollectionGeneratorSpecImpl(GeneratorContext context)
-
-
Method Detail
-
generate
public Collection<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.
-
isDelegating
public boolean isDelegating()
Description copied from interface:Generator
Iftrue
, then this generator delegate object instantiation to another generator supplied viaGenerator.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
, aHashSet
, or some other collection type.- Returns:
true
if this is a delegating generator
-
setDelegate
public void setDelegate(Generator<?> delegate)
Description copied from interface:Generator
Set a delegate that will be responsible for instantiating an object on behalf of this generator.- Parameters:
delegate
- that will create the target object
-
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 asHashSet
.- Returns:
- target class
-
-