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 iterableI
- 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 Summary
ConstructorsConstructorDescriptionFunctionalCollectionProvider
(@NotNull Supplier<I> defaultConstructor, @NotNull Function<I, I> copyConstructor, @NotNull Function<Collection<E>, I> collectionConstructor, @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. -
Method Summary
Modifier and TypeMethodDescriptioncreateInstance
(int seed) Creates a single instance of class being tested based upon an integer seed value.createInstance
(E[] elements) Creates an instance of iterable with the same elements provided.createInstance
(@NotNull Collection<E> c) Creates an instance of iterable with the same elements as in the specified collection.Create an iterable with a set of elements that does not contain any duplicate values.createInstanceWithUniqueElements
(int size) Create an iterable with a set of elements of a specified length that does not contain any duplicate values.createInstanceWithUniqueElements
(int size, int seed) 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.Creates an instance of iterable with a single element.createSingleton
(E e) Creates an instance of iterable with a single element.@NotNull ObjectProvider
<E> Returns the element provider used to create elements for instances of the collection.Creates an instance of iterable with no elements.static <E,
I extends Iterable<E>>
FunctionalCollectionProvider<E, I> from
(@NotNull Supplier<I> defaultConstructor, @NotNull Function<I, I> copyConstructor, @NotNull Function<Collection<E>, I> collectionConstructor, @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.Methods inherited from class org.soliscode.test.provider.FunctionalProvider
copyInstance, defaultInstance
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.soliscode.test.provider.ObjectProvider
copyInstance, createEqualObjects, createInstance, createRandoInstances, createUniqueInstances, createUniqueInstances, defaultInstance, equalInstanceSupplier, randomInstanceSupplier, uniqueInstanceSupplier, uniqueInstanceSupplier, uniqueSizeLimit
-
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 arenull
-
-
Method Details
-
elementProvider
Description copied from interface:CollectionProvider
Returns the element provider used to create elements for instances of the collection.- Specified by:
elementProvider
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Returns:
- the element provider.
-
emptyInstance
Creates an instance of iterable with no elements.- Specified by:
emptyInstance
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Returns:
- and instance of iterable
-
createInstance
Description copied from interface:CollectionProvider
Creates an instance of iterable with the same elements as in the specified collection.- Specified by:
createInstance
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Parameters:
c
- the elements to use for the iterable.- Returns:
- an instance of the iterable.
-
createInstance
Description copied from interface:ObjectProvider
Creates a single instance of class being tested based upon an integer seed value.- Specified by:
createInstance
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Specified by:
createInstance
in interfaceObjectProvider<E>
- Overrides:
createInstance
in classFunctionalProvider<I extends Iterable<E>>
- Parameters:
seed
- an integer seed to use to create and instance of the class.- Returns:
- an instance of class.
-
createSingleton
Description copied from interface:CollectionProvider
Creates an instance of iterable with a single element.- Specified by:
createSingleton
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Returns:
- and instance of the iterable
-
createSingleton
Creates an instance of iterable with a single element.- Specified by:
createSingleton
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Parameters:
e
- the element for the iterable.- Returns:
- and instance of iterable.
-
createInstance
Creates an instance of iterable with the same elements provided.- Specified by:
createInstance
in interfaceCollectionProvider<E,
I extends Iterable<E>> - Parameters:
elements
- the elements for the iterable.- Returns:
- and instance of iterable.
- Throws:
NullPointerException
- if the argument isnull
.
-
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 interfaceCollectionProvider<E,
I extends Iterable<E>> - Returns:
- an instance of the iterable.
-
createInstanceWithUniqueElements
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 interfaceCollectionProvider<E,
I extends Iterable<E>> - Parameters:
size
- the number of elements in the iterable.- Returns:
- an instance of the iterable.
-
createInstanceWithUniqueElements
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 interfaceCollectionProvider<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 arenull
-