Skip to content

Commit 70b8915

Browse files
committed
Added support for a delegating data loader - tweaked javadoc
1 parent 5452d73 commit 70b8915

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/java/org/dataloader/DelegatingDataLoader.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,24 @@
1616

1717
/**
1818
* This delegating {@link DataLoader} makes it easier to create wrappers of {@link DataLoader}s in case you want to change how
19-
* values are returned for example
20-
*
19+
* values are returned for example.
20+
* <p>
21+
* The most common way would be to make a new {@link DelegatingDataLoader} subclass that overloads the {@link DelegatingDataLoader#load(Object, Object)}
22+
* method.
23+
* <p>
24+
* For example the following allows you to change the returned value in some way :
25+
* <pre>
26+
* {@code
27+
* DataLoader<String, String> rawLoader = createDataLoader();
28+
* DelegatingDataLoader<String, String> delegatingDataLoader = new DelegatingDataLoader<>(rawLoader) {
29+
* @Override
30+
* public CompletableFuture<String> load(@NonNull String key, @Nullable Object keyContext) {
31+
* CompletableFuture<String> cf = super.load(key, keyContext);
32+
* return cf.thenApply(v -> "|" + v + "|");
33+
* }
34+
* };
35+
* }
36+
* </pre>
2137
* @param <K> type parameter indicating the type of the data load keys
2238
* @param <V> type parameter indicating the type of the data that is returned
2339
*/
@@ -65,7 +81,6 @@ public CompletableFuture<V> load(@NonNull K key, @Nullable Object keyContext) {
6581
return delegate.load(key, keyContext);
6682
}
6783

68-
6984
@Override
7085
public DataLoader<K, V> transform(Consumer<DataLoaderFactory.Builder<K, V>> builderConsumer) {
7186
return delegate.transform(builderConsumer);

src/test/java/org/dataloader/DelegatingDataLoaderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dataloader;
22

33
import org.dataloader.fixtures.TestKit;
4+
import org.dataloader.fixtures.parameterized.DelegatingDataLoaderFactory;
45
import org.jspecify.annotations.NonNull;
56
import org.jspecify.annotations.Nullable;
67
import org.junit.jupiter.api.Test;
@@ -14,7 +15,7 @@
1415
import static org.hamcrest.MatcherAssert.assertThat;
1516

1617
/**
17-
* There are WAY more tests via the {@link org.dataloader.fixtures.parameterized.DelegatingDataLoaderFactory}
18+
* There are WAY more tests via the {@link DelegatingDataLoaderFactory}
1819
* parameterized tests. All the basic {@link DataLoader} tests pass when wrapped in a {@link DelegatingDataLoader}
1920
*/
2021
public class DelegatingDataLoaderTest {

0 commit comments

Comments
 (0)