Class CollectionGenerator<T>

java.lang.Object
de.cuioss.test.generator.impl.CollectionGenerator<T>
Type Parameters:
T - identifying the type of the object being generated
All Implemented Interfaces:
TypedGenerator<T>

public class CollectionGenerator<T> extends Object implements TypedGenerator<T>
Wraps a given TypedGenerator and provides additional methods for creating Lists and Sets
Author:
Oliver Wolff
  • Constructor Details

    • CollectionGenerator

      public CollectionGenerator(TypedGenerator<T> wrapped, TypedGenerator<Integer> sizeGenerator)
      Parameters:
      wrapped - must not be null
      sizeGenerator - must not be null
    • CollectionGenerator

      public CollectionGenerator(TypedGenerator<T> wrapped, int lowerBound, int upperBound)
      Constructor.
      Parameters:
      wrapped - generator, must not be null
      lowerBound - defines the lower bound of the integer generator that determines the of Collection size
      upperBound - defines the upper bound of the integer generator that determines the of Collection size
    • CollectionGenerator

      Constructor. using 2 and 12 as bounds of the Collection size to be created.
      Parameters:
      wrapped - generator, must not be null
  • Method Details

    • next

      public T next()
      Description copied from interface: TypedGenerator
      Generates the next instance.
      Specified by:
      next in interface TypedGenerator<T>
      Returns:
      the next object from the contained TypedGenerator
    • list

      public List<T> list(int count)
      Returns a List of the elements provided by the generator
      Parameters:
      count - the number of elements within the list
      Returns:
      a list with a given number of elements.
    • set

      public Set<T> set(int count)
      Returns a Set of the elements provided by the generator
      Parameters:
      count - the number of elements within the Set. It defines an upper bound of elements, but depending on the elements / the entropy of the generator there may be a lower number of elements.
      Returns:
      a Set with a given number of elements as maximum.
    • sortedSet

      public SortedSet<T> sortedSet(int count)
      Returns a SortedSet of the elements provided by the generator
      Parameters:
      count - the number of elements within the Set. It defines an upper bound of elements, but depending on the elements / the entropy of the generator there may be a lower number of elements.
      Returns:
      a Set with a given number of elements as maximum.
    • set

      public Set<T> set()
      Returns:
      a Set with a random number of elements as maximum.
    • list

      public List<T> list()
      Returns:
      a List with a random number of elements as maximum.
    • sortedSet

      public SortedSet<T> sortedSet()
      Returns:
      a SortedSet with a random number of elements as maximum.
    • nextCollection

      public Iterable<T> nextCollection(Class<? extends Iterable<?>> expectedType)
      Generates a concrete Iterable. It is smart enough to determine whether the elements are to be wrapped in a List, Set, Collection or SortedSet.
      Parameters:
      expectedType - type of the expected Iterable
      Returns:
      depending on the given expectedType a corresponding Iterable, Collection, List, SortedSet or Set