Class 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 a chunkSize, this method chunks the elements into chunks with the chunkSize represented by a List 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 given List of SphereRequests, 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 of GraphQlBaseResult to the set of ChunkUtils.
      static <T> java.util.List<T> flattenPagedQueryResults​(java.util.List<io.sphere.sdk.queries.PagedQueryResult<T>> pagedQueryResults)
      Flat map the list of lists of PagedQueryResult to the list of ChunkUtils.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ChunkUtils

        public ChunkUtils()
    • 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 given List of SphereRequests, 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 of SphereRequest implementation to allow SphereClient 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 of PagedQueryResult to the list of ChunkUtils.
        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 of GraphQlBaseResult to the set of ChunkUtils.
        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 a chunkSize, this method chunks the elements into chunks with the chunkSize represented by a List of elements.
        Type Parameters:
        T - the type of the underlying model.
        Parameters:
        elements - the list of elements
        chunkSize - the size of each chunk.
        Returns:
        a list of lists where each list represents a chunk of elements.