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 Details

    • OfCollectionApiImpl

      public OfCollectionApiImpl(Class<C> collectionType, Class<T> elementType)
  • Method Details

    • fromElementModel

      public static <T, C extends Collection<T>> OfCollectionApiImpl<T,C> fromElementModel(Class<C> collectionType, Model<T> elementModel)
    • size

      public InstancioOfCollectionApi<C> size(int 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 interface InstancioOfCollectionApi<T>
      Parameters:
      size - of the collection to generate
      Returns:
      API builder reference