Package org.instancio

Interface InstancioOfCollectionApi<C>

Type Parameters:
C - collection type to create
All Superinterfaces:
InstancioApi<C>

public interface InstancioOfCollectionApi<C> extends InstancioApi<C>
Instancio API for generating collections populated with random data.
Since:
2.0.0
  • Method Details

    • size

      InstancioOfCollectionApi<C> size(int size)
      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();
       
      Parameters:
      size - of the collection to generate
      Returns:
      API builder reference
      Since:
      2.0.0