Class SyncUtils


  • public final class SyncUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.List<java.util.List<T>> batchElements​(java.util.List<T> elements, int batchSize)
      Given a list of elements and a batchSize, this method distributes the elements into batches with the batchSize.
      static <ResourceIdentifierT extends com.commercetools.api.models.common.ResourceIdentifier>
      ResourceIdentifierT
      getResourceIdentifierWithKey​(com.commercetools.api.models.common.Reference reference, ReferenceIdToKeyCache referenceIdToKeyCache, java.util.function.BiFunction<java.lang.String,​java.lang.String,​ResourceIdentifierT> toResourceIdentifierWithIdAndKey)
      Given a reference to a resource of type T, this method checks if the reference id is cached.
      static boolean isUuid​(java.lang.String id)
      Given an id as String, this method checks whether if it is in UUID format or not.
      • Methods inherited from class java.lang.Object

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

      • batchElements

        public static <T> java.util.List<java.util.List<T>> batchElements​(@Nonnull
                                                                          java.util.List<T> elements,
                                                                          int batchSize)
        Given a list of elements and a batchSize, this method distributes the elements into batches with the batchSize. Each batch is represented by a List of elements and all the batches are grouped and represented by a List<List> of elements, which is returned by the method.
        Type Parameters:
        T - the type of the draft elements.
        Parameters:
        elements - the list of elements to split into batches.
        batchSize - the size of each batch.
        Returns:
        a list of lists where each list represents a batch of elements.
      • getResourceIdentifierWithKey

        @Nullable
        public static <ResourceIdentifierT extends com.commercetools.api.models.common.ResourceIdentifier> ResourceIdentifierT getResourceIdentifierWithKey​(@Nullable
                                                                                                                                                            com.commercetools.api.models.common.Reference reference,
                                                                                                                                                            @Nonnull
                                                                                                                                                            ReferenceIdToKeyCache referenceIdToKeyCache,
                                                                                                                                                            @Nonnull
                                                                                                                                                            java.util.function.BiFunction<java.lang.String,​java.lang.String,​ResourceIdentifierT> toResourceIdentifierWithIdAndKey)
        Given a reference to a resource of type T, this method checks if the reference id is cached. If it is, then it returns the resource identifier with key. Otherwise, it returns the resource identifier with id. Since, the reference could be null, this method could also return null if the reference id was not in the map.
        Parameters:
        reference - the reference of the resource to check if it's cached.
        referenceIdToKeyCache - the instance that manages cache.
        toResourceIdentifierWithIdAndKey -
        Returns:
        returns the resource identifier with key if the reference id was in cache. Otherwise, it returns the resource identifier with id.
      • isUuid

        public static boolean isUuid​(@Nonnull
                                     java.lang.String id)
        Given an id as String, this method checks whether if it is in UUID format or not.
        Parameters:
        id - to check if it is in UUID format.
        Returns:
        true if it is in UUID format, otherwise false.