The type of the batch response.
*/
-public interface AsyncBatchServiceCaller
extends BatchServiceCaller
, ConcurrentOperationSupport {
+public interface AsyncBatchServiceCaller
+ extends BatchServiceCaller
, ConcurrentOperationSupport {
}
diff --git a/src/main/java/com/github/nagyesta/cacheonly/raw/exception/BatchServiceException.java b/src/main/java/com/github/nagyesta/cacheonly/raw/exception/BatchServiceException.java
index c7172b0..417a596 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/raw/exception/BatchServiceException.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/raw/exception/BatchServiceException.java
@@ -23,8 +23,9 @@ public BatchServiceException(final @NotNull String message) {
* @param message The message detailing the failure.
* @param cause The cause of the failure.
*/
- public BatchServiceException(final @NotNull String message,
- final @NotNull Throwable cause) {
+ public BatchServiceException(
+ final @NotNull String message,
+ final @NotNull Throwable cause) {
super(message, cause);
}
}
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/BatchRequestTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/BatchRequestTransformer.java
index 7b60fa1..a39473b 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/BatchRequestTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/BatchRequestTransformer.java
@@ -10,7 +10,7 @@
*
* @param The type of the batch request.
* @param The type of the partial request.
- * @param The type of the Id that can identify a partial request in the scope
+ * @param The type of the ID that can identify a partial request in the scope
* of a batch.
*/
public interface BatchRequestTransformer {
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/BatchResponseTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/BatchResponseTransformer.java
index d43b823..1a7832b 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/BatchResponseTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/BatchResponseTransformer.java
@@ -10,7 +10,7 @@
*
* @param The type of the batch response.
* @param
The type of the partial response.
- * @param The type of the Id that can identify a partial response and pair it
+ * @param The type of the ID that can identify a partial response and pair it
* with a partial request of a batch request we try to respond to.
*/
public interface BatchResponseTransformer {
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/NoOpPartialCacheSupport.java b/src/main/java/com/github/nagyesta/cacheonly/transform/NoOpPartialCacheSupport.java
index 96b833c..6b48059 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/NoOpPartialCacheSupport.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/NoOpPartialCacheSupport.java
@@ -37,7 +37,9 @@ public CacheKey toCacheKey(final @NotNull PR partialRequest) {
}
@Override
- public void putToCache(final @NotNull CacheKey key, final @NotNull PS entity) {
+ public void putToCache(
+ final @NotNull CacheKey key,
+ final @NotNull PS entity) {
//noop
}
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/PartialCacheSupport.java b/src/main/java/com/github/nagyesta/cacheonly/transform/PartialCacheSupport.java
index e458a72..3685d99 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/PartialCacheSupport.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/PartialCacheSupport.java
@@ -6,6 +6,8 @@
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
+import java.util.Optional;
+
/**
* Defines how a given partial request-response pair should be cached.
*
@@ -54,7 +56,7 @@ public interface PartialCacheSupport {
*
* @return The cache
*/
- @NotNull
+ @Nullable
default Cache obtainCache() {
return getCacheManager().getCache(cacheName());
}
@@ -66,7 +68,8 @@ default Cache obtainCache() {
* @param entity The entity we want to cache.
*/
default void putToCache(final @NotNull CacheKey key, final @NotNull PS entity) {
- obtainCache().put(key.getKey(), entity);
+ Optional.ofNullable(obtainCache())
+ .ifPresent(cache -> cache.put(key.key(), entity));
}
/**
@@ -77,6 +80,8 @@ default void putToCache(final @NotNull CacheKey key, final @NotNull PS ent
*/
@Nullable
default PS getFromCache(final @NotNull CacheKey key) {
- return obtainCache().get(key.getKey(), getEntityClass());
+ return Optional.ofNullable(obtainCache())
+ .map(cache -> cache.get(key.key(), getEntityClass()))
+ .orElse(null);
}
}
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractCollectionBasedTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractCollectionBasedTransformer.java
index d65b9da..a9b2791 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractCollectionBasedTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractCollectionBasedTransformer.java
@@ -27,10 +27,11 @@ public class AbstractCollectionBasedTransformer, P, I> {
* Creates a new instance and defines how the {@link Collection} should be collected from a {@link java.util.stream.Stream}.
*
* @param collectionCollector The {@link Collector} we want to use to get a batch from a stream of elements.
- * @param idFunction The transformation that can determine the Id of a given partial request (or response).
+ * @param idFunction The transformation that can determine the ID of a given partial request (or response).
*/
- public AbstractCollectionBasedTransformer(final @NotNull Collector collectionCollector,
- final @NotNull Function
idFunction) {
+ public AbstractCollectionBasedTransformer(
+ final @NotNull Collector
collectionCollector,
+ final @NotNull Function
idFunction) {
this(collectionCollector, idFunction, false);
}
@@ -38,12 +39,13 @@ public AbstractCollectionBasedTransformer(final @NotNull Collector
coll
* Creates a new instance and defines how the {@link Collection} should be collected from a {@link java.util.stream.Stream}.
*
* @param collectionCollector The {@link Collector} we want to use to get a batch from a stream of elements.
- * @param idFunction The transformation that can determine the Id of a given partial request (or response).
+ * @param idFunction The transformation that can determine the ID of a given partial request (or response).
* @param nullIfEmpty Flag telling the implementation whether we want to use null in case of an empty {@link Collection}.
*/
- public AbstractCollectionBasedTransformer(final @NotNull Collector
collectionCollector,
- final @NotNull Function
idFunction,
- final boolean nullIfEmpty) {
+ public AbstractCollectionBasedTransformer(
+ final @NotNull Collector
collectionCollector,
+ final @NotNull Function
idFunction,
+ final boolean nullIfEmpty) {
this.collectionCollector = collectionCollector;
this.idFunction = idFunction;
this.nullIfEmpty = nullIfEmpty;
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractMapBasedTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractMapBasedTransformer.java
index b319e2a..82b72bc 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractMapBasedTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractMapBasedTransformer.java
@@ -10,7 +10,7 @@
/**
* Abstract transformer intended to be used in cases when the batch request (or response)
- * is a simple {@link Map} of the partial requests (or responses) using the Id as key.
+ * is a simple {@link Map} of the partial requests (or responses) using the ID as key.
*
* @param The {@link Map} type used for the batch.
* @param The type of the partial request (or response) payload.
@@ -28,7 +28,8 @@ public class AbstractMapBasedTransformer, P, I> {
*
* @param mergeMapCollector The collector we want to use when we merge partials to a batch.
*/
- public AbstractMapBasedTransformer(final @NotNull Collector, ?, C> mergeMapCollector) {
+ public AbstractMapBasedTransformer(
+ final @NotNull Collector, ?, C> mergeMapCollector) {
this(mergeMapCollector, Map.Entry::getKey, Map.Entry::getValue, false);
}
@@ -42,10 +43,11 @@ public AbstractMapBasedTransformer(final @NotNull Collector, ?,
* an Entry to a value in the partial entry.
* @param nullIfEmpty True is we need to return null in case we are merging an empty map.
*/
- public AbstractMapBasedTransformer(final @NotNull Collector, ?, C> mergeMapCollector,
- final @NotNull Function, I> splitKeyTransformer,
- final @NotNull Function, P> splitValueTransformer,
- final boolean nullIfEmpty) {
+ public AbstractMapBasedTransformer(
+ final @NotNull Collector, ?, C> mergeMapCollector,
+ final @NotNull Function, I> splitKeyTransformer,
+ final @NotNull Function, P> splitValueTransformer,
+ final boolean nullIfEmpty) {
this.mergeMapCollector = mergeMapCollector;
this.splitKeyTransformer = splitKeyTransformer;
this.splitValueTransformer = splitValueTransformer;
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedCollectionBasedTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedCollectionBasedTransformer.java
index f5ab2da..c380fd6 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedCollectionBasedTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedCollectionBasedTransformer.java
@@ -20,7 +20,7 @@
* @param The type of the batch wrapper class.
* @param The type of the {@link Collection} holding the values we want to partition.
* @param The type of the partial entities.
- * @param The type of the Id we can use for partial entity identification.
+ * @param The type of the ID we can use for partial entity identification.
*/
public class AbstractWrappedCollectionBasedTransformer, E, I> {
@@ -31,37 +31,39 @@ public class AbstractWrappedCollectionBasedTransformer idFunction;
/**
- * Creates a new instance and sets all of the parameters we can use for customization.
+ * Creates a new instance and sets all the parameters we can use for customization.
*
* @param instanceSupplier The {@link Supplier} we can use for getting a new empty batch instance.
* @param collectionReadFunction The function that can read the collection from a batch.
* @param collectionWriteBiFunction The function that can write the collection into a batch.
* @param collectionCollector The collector creating a new collection from the partial entities.
- * @param idFunction The function that can convert an entity to the Id identifying it.
+ * @param idFunction The function that can convert an entity to the ID identifying it.
*/
- public AbstractWrappedCollectionBasedTransformer(final @NotNull Supplier instanceSupplier,
- final @NotNull Function collectionReadFunction,
- final @NotNull BiFunction collectionWriteBiFunction,
- final @NotNull Collector collectionCollector,
- final @NotNull Function idFunction) {
+ public AbstractWrappedCollectionBasedTransformer(
+ final @NotNull Supplier instanceSupplier,
+ final @NotNull Function collectionReadFunction,
+ final @NotNull BiFunction collectionWriteBiFunction,
+ final @NotNull Collector collectionCollector,
+ final @NotNull Function idFunction) {
this(response -> cloneWrapper(response, instanceSupplier), collectionReadFunction,
collectionWriteBiFunction, collectionCollector, idFunction);
}
/**
- * Creates a new instance and sets all of the parameters we can use for customization.
+ * Creates a new instance and sets all the parameters we can use for customization.
*
* @param cloneFunction The function that can clone a batch.
* @param collectionReadFunction The function that can read the collection from a batch.
* @param collectionWriteBiFunction The function that can write the collection into a batch.
* @param collectionCollector The collector creating a new collection from the partial entities.
- * @param idFunction The function that can convert an entity to the Id identifying it.
+ * @param idFunction The function that can convert an entity to the ID identifying it.
*/
- public AbstractWrappedCollectionBasedTransformer(final @NotNull Function cloneFunction,
- final @NotNull Function collectionReadFunction,
- final @NotNull BiFunction collectionWriteBiFunction,
- final @NotNull Collector collectionCollector,
- final @NotNull Function idFunction) {
+ public AbstractWrappedCollectionBasedTransformer(
+ final @NotNull Function cloneFunction,
+ final @NotNull Function collectionReadFunction,
+ final @NotNull BiFunction collectionWriteBiFunction,
+ final @NotNull Collector collectionCollector,
+ final @NotNull Function idFunction) {
this.cloneFunction = cloneFunction;
this.collectionReadFunction = collectionReadFunction;
this.collectionWriteBiFunction = collectionWriteBiFunction;
@@ -70,8 +72,10 @@ public AbstractWrappedCollectionBasedTransformer(final @NotNull Function c
}
@NotNull
- private static B cloneWrapper(final @NotNull B batch, final @NotNull Supplier instanceSupplier) {
- final B target = instanceSupplier.get();
+ private static B cloneWrapper(
+ final @NotNull B batch,
+ final @NotNull Supplier instanceSupplier) {
+ final var target = instanceSupplier.get();
BeanUtils.copyProperties(batch, target);
return target;
}
diff --git a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedMapBasedTransformer.java b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedMapBasedTransformer.java
index 00dffe4..8fd9fb0 100644
--- a/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedMapBasedTransformer.java
+++ b/src/main/java/com/github/nagyesta/cacheonly/transform/common/AbstractWrappedMapBasedTransformer.java
@@ -20,7 +20,7 @@
* @param The type of the batch wrapper class.
* @param The type of the {@link Map} holding the values we want to partition.
* @param The type of the partial entities.
- * @param The type of the Id we can use for partial entity identification.
+ * @param