Class FunctionalCollectionProvider<E,I extends Iterable<E>>

java.lang.Object
org.soliscode.test.provider.FunctionalProvider<I>
org.soliscode.test.provider.FunctionalCollectionProvider<E,I>
Type Parameters:
E - the element type for the iterable
I - the iterable type.
All Implemented Interfaces:
CollectionProvider<E,I>, ObjectProvider<I>

public class FunctionalCollectionProvider<E,I extends Iterable<E>> extends FunctionalProvider<I> implements CollectionProvider<E,I>

A collection provider that uses a set of functions to construct instances of the collection. There are four elements required to create a collection provider using this class:

  • Default constructor function
  • Copy constructor function
  • Collection constructor function
  • Element provider. For example, to create a collection provider for an ArrayList of Integer objects:
    CollectionProvider<Integer> provider = FunctionalCollectionProvider<Integer, ArrayList>(
        ArrayList;:new, ArrayList::new, ArrayList::new, Providers.integerProvider());
Since:
1.0.0
Author:
evanbergstrom
  • Constructor Details

    • FunctionalCollectionProvider

      public FunctionalCollectionProvider(@NotNull @NotNull Supplier<I> defaultConstructor, @NotNull @NotNull Function<I,I> copyConstructor, @NotNull @NotNull Function<Collection<E>,I> collectionConstructor, @NotNull @NotNull ObjectProvider<E> elementProvider)
      Create an instance of this collection provider that uses the methods and element provider specified in the arguments for its implementation.
      Parameters:
      defaultConstructor - the supplier to use to create default instances of the collection.
      copyConstructor - the function to use to create a copy of the collection.
      collectionConstructor - the function to use to create an instance from another collection.
      elementProvider - the element provider.
      Throws:
      NullPointerException - if any of the arguments are null
  • Method Details

    • elementProvider

      @NotNull public @NotNull ObjectProvider<E> elementProvider()
      Description copied from interface: CollectionProvider
      Returns the element provider used to create elements for instances of the collection.
      Specified by:
      elementProvider in interface CollectionProvider<E,I extends Iterable<E>>
      Returns:
      the element provider.
    • emptyInstance

      @NotNull public I emptyInstance()
      Creates an instance of iterable with no elements.
      Specified by:
      emptyInstance in interface CollectionProvider<E,I extends Iterable<E>>
      Returns:
      and instance of iterable
    • createInstance

      @NotNull public I createInstance(@NotNull @NotNull Collection<E> c)
      Description copied from interface: CollectionProvider
      Creates an instance of iterable with the same elements as in the specified collection.
      Specified by:
      createInstance in interface CollectionProvider<E,I extends Iterable<E>>
      Parameters:
      c - the elements to use for the iterable.
      Returns:
      an instance of the iterable.
    • createInstance

      @NotNull public I createInstance(int seed)
      Description copied from interface: ObjectProvider
      Creates a single instance of class being tested based upon an integer seed value.
      Specified by:
      createInstance in interface CollectionProvider<E,I extends Iterable<E>>
      Specified by:
      createInstance in interface ObjectProvider<E>
      Overrides:
      createInstance in class FunctionalProvider<I extends Iterable<E>>
      Parameters:
      seed - an integer seed to use to create and instance of the class.
      Returns:
      an instance of class.
    • createSingleton

      @NotNull public I createSingleton()
      Description copied from interface: CollectionProvider
      Creates an instance of iterable with a single element.
      Specified by:
      createSingleton in interface CollectionProvider<E,I extends Iterable<E>>
      Returns:
      and instance of the iterable
    • createSingleton

      @NotNull public I createSingleton(E e)
      Creates an instance of iterable with a single element.
      Specified by:
      createSingleton in interface CollectionProvider<E,I extends Iterable<E>>
      Parameters:
      e - the element for the iterable.
      Returns:
      and instance of iterable.
    • createInstance

      @NotNull public I createInstance(@NotNull E[] elements)
      Creates an instance of iterable with the same elements provided.
      Specified by:
      createInstance in interface CollectionProvider<E,I extends Iterable<E>>
      Parameters:
      elements - the elements for the iterable.
      Returns:
      and instance of iterable.
      Throws:
      NullPointerException - if the argument is null.
    • createInstanceWithUniqueElements

      @NotNull public I createInstanceWithUniqueElements()
      Description copied from interface: CollectionProvider
      Create an iterable with a set of elements that does not contain any duplicate values.
      Specified by:
      createInstanceWithUniqueElements in interface CollectionProvider<E,I extends Iterable<E>>
      Returns:
      an instance of the iterable.
    • createInstanceWithUniqueElements

      @NotNull public I createInstanceWithUniqueElements(int size)
      Description copied from interface: CollectionProvider
      Create an iterable with a set of elements of a specified length that does not contain any duplicate values.
      Specified by:
      createInstanceWithUniqueElements in interface CollectionProvider<E,I extends Iterable<E>>
      Parameters:
      size - the number of elements in the iterable.
      Returns:
      an instance of the iterable.
    • createInstanceWithUniqueElements

      @NotNull public I createInstanceWithUniqueElements(int size, int seed)
      Description copied from interface: CollectionProvider
      Create an iterable with a set of elements of a specified length and using the specified seed value that does not contain any duplicate values.
      Specified by:
      createInstanceWithUniqueElements in interface CollectionProvider<E,I extends Iterable<E>>
      Parameters:
      size - the number of elements in the iterable.
      seed - the seed value to use to create the elements.
      Returns:
      an instance of the iterable.
    • from

      public static <E, I extends Iterable<E>> FunctionalCollectionProvider<E,I> from(@NotNull @NotNull Supplier<I> defaultConstructor, @NotNull @NotNull Function<I,I> copyConstructor, @NotNull @NotNull Function<Collection<E>,I> collectionConstructor, @NotNull @NotNull ObjectProvider<E> elementProvider)
      Create an instance of this collection provider that uses the methods and element provider specified in the arguments for its implementation.
      Type Parameters:
      E - the type of the elements.
      I - the type of the iterable.
      Parameters:
      defaultConstructor - the supplier to use to create default instances of the collection.
      copyConstructor - the function to use to create a copy of the collection.
      collectionConstructor - the function to use to create an instance from another collection.
      elementProvider - the element provider.
      Returns:
      the collection provider.
      Throws:
      NullPointerException - if any of the arguments are null