Class CollectionProviders
java.lang.Object
org.soliscode.test.provider.CollectionProviders
Utility class for creating collection providers.
- Since:
- 1.0
- Author:
- evanbergstrom
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E,
C extends Iterable<E>>
CollectionProvider<E, C> from
(@NotNull Supplier<C> defaultConstructor, @NotNull Function<C, C> copyConstructor, @NotNull Function<Collection<E>, C> 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.static <E> @NotNull CollectionProvider
<E, ArrayList<E>> provideArrayList
(@NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofArrayList
with elements creates using the specifiedstatic <E> CollectionProvider
<E, HashSet<E>> provideHashSet
(@NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofHashSet
with elements creates using the specifiedstatic <E> CollectionProvider
<E, LinkedList<E>> provideLinkedList
(@NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofLinkedList
with elements creates using the specifiedstatic <E,
C extends Collection<E>, W extends Collection<E>>
CollectionProvider<E, W> wrap
(CollectionProvider<E, C> provider, Function<C, W> wrapper) Creates a provider that wraps the provided collection from an underlying provider.
-
Method Details
-
from
public static <E,C extends Iterable<E>> CollectionProvider<E,C> from(@NotNull @NotNull Supplier<C> defaultConstructor, @NotNull @NotNull Function<C, C> copyConstructor, @NotNull @NotNull Function<Collection<E>, C> 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.
For example, to create a collection provider for an
ArrayList
of Integer objects:CollectionProvider<Integer> provider = CollectionProviders.from(ArrayList::new, ArrayList::new, ArrayList::new, Providers.integerProvider());
- Type Parameters:
E
- the element type.C
- the collection type.- 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
-
provideArrayList
@NotNull public static <E> @NotNull CollectionProvider<E,ArrayList<E>> provideArrayList(@NotNull @NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofArrayList
with elements creates using the specified- Type Parameters:
E
- The type of the elements- Parameters:
elementProvider
- the provider to use to create the elements.- Returns:
- the collection provider.
-
provideLinkedList
public static <E> CollectionProvider<E,LinkedList<E>> provideLinkedList(@NotNull @NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofLinkedList
with elements creates using the specified- Type Parameters:
E
- The type of the elements- Parameters:
elementProvider
- the provider to use to create the elements.- Returns:
- the collection provider.
-
provideHashSet
public static <E> CollectionProvider<E,HashSet<E>> provideHashSet(@NotNull @NotNull ObjectProvider<E> elementProvider) Creates a collection provider for instances ofHashSet
with elements creates using the specified- Type Parameters:
E
- The type of the elements- Parameters:
elementProvider
- the provider to use to create the elements.- Returns:
- the collection provider.
-
wrap
public static <E,C extends Collection<E>, CollectionProvider<E,W extends Collection<E>> W> wrap(CollectionProvider<E, C> provider, Function<C, W> wrapper) Creates a provider that wraps the provided collection from an underlying provider.- Type Parameters:
E
- the element type.C
- the collection type provided by the underlying collection.W
- the collection type of the wrapped collection.- Parameters:
provider
- the underlying provider.wrapper
- the function used to wrap the provided collection.- Returns:
- the wrapped collection.
-