Package org.instancio.internal
Class OfCollectionApiImpl<T,C extends Collection<T>>
java.lang.Object
org.instancio.internal.ApiImpl<T>
org.instancio.internal.OfClassApiImpl<C>
org.instancio.internal.OfCollectionApiImpl<T,C>
- All Implemented Interfaces:
InstancioApi<C>
,InstancioOfClassApi<C>
,InstancioOfCollectionApi<C>
public final class OfCollectionApiImpl<T,C extends Collection<T>>
extends OfClassApiImpl<C>
implements InstancioOfCollectionApi<C>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
C extends Collection<T>>
OfCollectionApiImpl<T,C> fromElementModel
(Class<C> collectionType, Model<T> elementModel) size
(int size) Specifies collection size to generate.Methods inherited from class org.instancio.internal.OfClassApiImpl
withTypeParameters
Methods inherited from class org.instancio.internal.ApiImpl
addTypeParameters, asResult, create, generate, generate, ignore, lenient, onComplete, set, stream, subtype, supply, supply, toModel, withMaxDepth, withNullable, withSeed, withSettings
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.instancio.InstancioApi
asResult, create, generate, generate, ignore, lenient, onComplete, set, stream, subtype, supply, supply, toModel, withMaxDepth, withNullable, withSeed, withSettings
-
Constructor Details
-
OfCollectionApiImpl
-
-
Method Details
-
fromElementModel
public static <T,C extends Collection<T>> OfCollectionApiImpl<T,C> fromElementModel(Class<C> collectionType, Model<T> elementModel) -
size
Description copied from interface:InstancioOfCollectionApi
Specifies collection size to generate.This method is syntactic sugar for:
List<Integer> result = Instancio.ofList(Integer.class) .generate(root(), gen -> gen.collection().size(50)) .create();
Therefore, if you modify the collection generator via
root()
selector (for example, to specify the collection's type) then you will need to specify the size using the generator as well.For example, instead of:
List<Integer> result = Instancio.ofList(Integer.class) .size(50) .generate(root(), gen -> gen.collection().subtype(LinkedList.class)) .create();
use:
List<Integer> result = Instancio.ofList(Integer.class) .generate(root(), gen -> gen.collection().subtype(LinkedList.class).size(50)) .create();
- Specified by:
size
in interfaceInstancioOfCollectionApi<T>
- Parameters:
size
- of the collection to generate- Returns:
- API builder reference
-