public final class SyncUtils
extends java.lang.Object
Modifier and Type | Method and 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 <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 type
T , this method checks if the reference id is
cached in the map. |
static <T extends io.sphere.sdk.models.WithKey> |
getResourceIdentifierWithKey(io.sphere.sdk.models.Reference<T> reference,
ReferenceIdToKeyCache referenceIdToKeyCache)
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. |
public static <T> java.util.List<java.util.List<T>> batchElements(@Nonnull java.util.List<T> elements, int batchSize)
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.T
- the type of the draft elements.elements
- the list of elements to split into batches.batchSize
- the size of each batch.@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)
T
, this method checks if the reference id is
cached in the map. If it is, then it executes the keyInReferenceSupplier
and returns
it's result. Otherwise, it returns the supplied reference as is. Since, the reference could be
null
, this method could also return null if the reference id is not in the map.
This method expects the passed supplier to either
T
- the type of the resource.reference
- the reference of the resource to check if it's cached.keyInReferenceSupplier
- the supplier to execute and return its result if the reference
was cached.referenceIdToKeyCache
- the instance that manages cache.keyInReferenceSupplier
if the reference
id
was in cache. Otherwise, it returns the supplied reference as is.@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)
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.T
- the type of the resource.reference
- the reference of the resource to check if it's cached.referenceIdToKeyCache
- the instance that manages cache.reference
id was in cache.
Otherwise, it returns the resource identifier with id.public static boolean isUuid(@Nonnull java.lang.String id)
String
, this method checks whether if it is in UUID format or not.id
- to check if it is in UUID format.