Class ChunkUtils
- java.lang.Object
-
- com.commercetools.sync.commons.utils.ChunkUtils
-
public class ChunkUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ChunkUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.List<java.util.List<T>>
chunk(java.util.Collection<T> elements, int chunkSize)
Given a collection of items and achunkSize
, this method chunks the elements into chunks with thechunkSize
represented by aList
of elements.static <T,Q extends io.sphere.sdk.client.SphereRequest<T>>
java.util.concurrent.CompletableFuture<java.util.List<T>>executeChunks(io.sphere.sdk.client.SphereClient client, java.util.List<Q> requests)
Executes the givenList
ofSphereRequest
s, and collects results in a list.static <T extends GraphQlBaseResult<U>,U extends GraphQlBaseResource>
java.util.Set<U>flattenGraphQLBaseResults(java.util.List<T> graphQlBaseResults)
Flat map the list of lists ofGraphQlBaseResult
to the set ofChunkUtils
.static <T> java.util.List<T>
flattenPagedQueryResults(java.util.List<io.sphere.sdk.queries.PagedQueryResult<T>> pagedQueryResults)
Flat map the list of lists ofPagedQueryResult
to the list ofChunkUtils
.
-
-
-
Method Detail
-
executeChunks
public static <T,Q extends io.sphere.sdk.client.SphereRequest<T>> java.util.concurrent.CompletableFuture<java.util.List<T>> executeChunks(@Nonnull io.sphere.sdk.client.SphereClient client, @Nonnull java.util.List<Q> requests)
Executes the givenList
ofSphereRequest
s, and collects results in a list.- Type Parameters:
T
- the type of the underlying model.Q
- the type of the request model.- Parameters:
client
-SphereClient
responsible for interaction with the target CTP project.requests
- A list ofSphereRequest
implementation to allowSphereClient
to execute queries on CTP.- Returns:
- a list of lists where each list represents the results of passed
SphereRequest
.
-
flattenPagedQueryResults
public static <T> java.util.List<T> flattenPagedQueryResults(@Nonnull java.util.List<io.sphere.sdk.queries.PagedQueryResult<T>> pagedQueryResults)
Flat map the list of lists ofPagedQueryResult
to the list ofChunkUtils
.- Type Parameters:
T
- the type of the underlying model.- Parameters:
pagedQueryResults
- query responses which contains a subset of the matching values.- Returns:
- a list of
ChunkUtils
-
flattenGraphQLBaseResults
public static <T extends GraphQlBaseResult<U>,U extends GraphQlBaseResource> java.util.Set<U> flattenGraphQLBaseResults(@Nonnull java.util.List<T> graphQlBaseResults)
Flat map the list of lists ofGraphQlBaseResult
to the set ofChunkUtils
.- Type Parameters:
U
- the type of the resource model.T
- the type of the generic result type.- Parameters:
graphQlBaseResults
- query responses which contains a subset of the matching values.- Returns:
- a set of
ChunkUtils
-
chunk
public static <T> java.util.List<java.util.List<T>> chunk(@Nonnull java.util.Collection<T> elements, int chunkSize)
Given a collection of items and achunkSize
, this method chunks the elements into chunks with thechunkSize
represented by aList
of elements.- Type Parameters:
T
- the type of the underlying model.- Parameters:
elements
- the list of elementschunkSize
- the size of each chunk.- Returns:
- a list of lists where each list represents a chunk of elements.
-
-