Class SyncUtils
- java.lang.Object
-
- com.commercetools.sync.commons.utils.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 abatchSize
, this method distributes the elements into batches with thebatchSize
.static <T> io.sphere.sdk.models.Reference<T>
getReferenceWithKeyReplaced(io.sphere.sdk.models.Reference<T> reference, java.util.function.Supplier<io.sphere.sdk.models.Reference<T>> keyInReferenceSupplier, ReferenceIdToKeyCache referenceIdToKeyCache)
Given a reference to a resource of typeT
, this method checks if the reference id is cached in the map.static <T extends io.sphere.sdk.models.WithKey>
io.sphere.sdk.models.ResourceIdentifier<T>getResourceIdentifierWithKey(io.sphere.sdk.models.Reference<T> reference, ReferenceIdToKeyCache referenceIdToKeyCache)
Given a reference to a resource of typeT
, this method checks if the reference id is cached.static boolean
isUuid(java.lang.String id)
Given an id asString
, this method checks whether if it is in UUID format or not.
-
-
-
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 abatchSize
, this method distributes the elements into batches with thebatchSize
. Each batch is represented by aList
of elements and all the batches are grouped and represented by aList
<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.
-
getReferenceWithKeyReplaced
@Nullable public static <T> io.sphere.sdk.models.Reference<T> getReferenceWithKeyReplaced(@Nullable io.sphere.sdk.models.Reference<T> reference, @Nonnull java.util.function.Supplier<io.sphere.sdk.models.Reference<T>> keyInReferenceSupplier, @Nonnull ReferenceIdToKeyCache referenceIdToKeyCache)
Given a reference to a resource of typeT
, this method checks if the reference id is cached in the map. If it is, then it executes thekeyInReferenceSupplier
and returns it's result. Otherwise, it returns the supplied reference as is. Since, the reference could benull
, this method could also return null if the reference id is not in the map.This method expects the passed supplier to either
- Type Parameters:
T
- the type of the resource.- Parameters:
reference
- the reference of the resource to check if it's cached.keyInReferenceSupplier
- the supplier to execute and return its result if thereference
was cached.referenceIdToKeyCache
- the instance that manages cache.- Returns:
- returns the result of the
keyInReferenceSupplier
if thereference
id was in cache. Otherwise, it returns the supplied reference as is.
-
getResourceIdentifierWithKey
@Nullable public static <T extends io.sphere.sdk.models.WithKey> io.sphere.sdk.models.ResourceIdentifier<T> getResourceIdentifierWithKey(@Nullable io.sphere.sdk.models.Reference<T> reference, @Nonnull ReferenceIdToKeyCache referenceIdToKeyCache)
Given a reference to a resource of typeT
, 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 benull
, this method could also return null if the reference id was not in the map.- Type Parameters:
T
- the type of the resource.- Parameters:
reference
- the reference of the resource to check if it's cached.referenceIdToKeyCache
- the instance that manages cache.- 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 asString
, 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.
-
-