Package org.instancio.generator.util
Class CollectionGenerator<T>
- java.lang.Object
-
- org.instancio.generator.AbstractRandomGenerator<Collection<T>>
-
- org.instancio.generator.util.CollectionGenerator<T>
-
- All Implemented Interfaces:
Generator<Collection<T>>
,GeneratorSpec<Collection<T>>
,CollectionGeneratorSpec<T>
- Direct Known Subclasses:
CollectionGeneratorSpecImpl
,HashSetGenerator
,TreeSetGenerator
public class CollectionGenerator<T> extends AbstractRandomGenerator<Collection<T>> implements CollectionGeneratorSpec<T>
-
-
Constructor Summary
Constructors Constructor Description CollectionGenerator(GeneratorContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<T>
generate()
Returns a generated value.GeneratedHints
getHints()
Returns hints, including collection sizes and whether values are nullable.CollectionGeneratorSpec<T>
maxSize(int size)
Maximum size of collection to generate.CollectionGeneratorSpec<T>
minSize(int size)
Minimum size of collection to generate.CollectionGeneratorSpec<T>
nullable()
Indicates thatnull
value can be generated for the collection.CollectionGeneratorSpec<T>
nullableElements()
Indicates thatnull
values can be generated for collection elements.CollectionGeneratorSpec<T>
size(int size)
Size of collection to generate.CollectionGeneratorSpec<T>
type(Class<?> type)
Specifies the type of collection that should be generated.-
Methods inherited from class org.instancio.generator.AbstractRandomGenerator
getContext, random
-
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
isDelegating, setDelegate, targetClass
-
-
-
-
Field Detail
-
minSize
protected int minSize
-
maxSize
protected int maxSize
-
nullable
protected boolean nullable
-
nullableElements
protected boolean nullableElements
-
type
protected Class<?> type
-
-
Constructor Detail
-
CollectionGenerator
public CollectionGenerator(GeneratorContext context)
-
-
Method Detail
-
size
public CollectionGeneratorSpec<T> size(int size)
Description copied from interface:CollectionGeneratorSpec
Size of collection to generate.- Specified by:
size
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- of collection- Returns:
- spec builder
-
minSize
public CollectionGeneratorSpec<T> minSize(int size)
Description copied from interface:CollectionGeneratorSpec
Minimum size of collection to generate.- Specified by:
minSize
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- minimum size (inclusive)- Returns:
- spec builder
-
maxSize
public CollectionGeneratorSpec<T> maxSize(int size)
Description copied from interface:CollectionGeneratorSpec
Maximum size of collection to generate.- Specified by:
maxSize
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- maximum size (inclusive)- Returns:
- spec builder
-
nullable
public CollectionGeneratorSpec<T> nullable()
Description copied from interface:CollectionGeneratorSpec
Indicates thatnull
value can be generated for the collection.- Specified by:
nullable
in interfaceCollectionGeneratorSpec<T>
- Returns:
- spec builder
-
nullableElements
public CollectionGeneratorSpec<T> nullableElements()
Description copied from interface:CollectionGeneratorSpec
Indicates thatnull
values can be generated for collection elements.- Specified by:
nullableElements
in interfaceCollectionGeneratorSpec<T>
- Returns:
- spec builder
-
type
public CollectionGeneratorSpec<T> type(Class<?> type)
Description copied from interface:CollectionGeneratorSpec
Specifies the type of collection that should be generated.- Specified by:
type
in interfaceCollectionGeneratorSpec<T>
- Parameters:
type
- of collection to generate- Returns:
- spec builder
-
generate
public Collection<T> generate()
Description copied from interface:Generator
Returns a generated value. By default, generated values are random.Generation parameters for common types such as strings, numbers, collections, etc. can be customised by passing in custom generators.
-
getHints
public GeneratedHints getHints()
Description copied from interface:Generator
Returns hints, including collection sizes and whether values are nullable.
-
-