diff --git a/src/main/java/tech/picnic/jolo/Loader.java b/src/main/java/tech/picnic/jolo/Loader.java index fe274fe..215cac1 100644 --- a/src/main/java/tech/picnic/jolo/Loader.java +++ b/src/main/java/tech/picnic/jolo/Loader.java @@ -6,6 +6,7 @@ import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; +import java.util.stream.Collector; import java.util.stream.Collectors; import java.util.stream.Stream; import org.jooq.Record; @@ -65,9 +66,14 @@ public Stream stream() { return get().stream(); } + /** Collects and then returns all objects loaded by this loader. */ + public R collect(Collector collector) { + return stream().collect(collector); + } + /** Returns all objects loaded by this loader. */ public List getList() { - return stream().collect(Collectors.toList()); + return collect(Collectors.toList()); } /** @@ -76,7 +82,7 @@ public List getList() { * correct result. */ public Set getSet() { - return stream().collect(Collectors.toSet()); + return collect(Collectors.toSet()); } /** diff --git a/src/test/java/tech/picnic/jolo/LoaderTest.java b/src/test/java/tech/picnic/jolo/LoaderTest.java index 078744d..7ca6d53 100644 --- a/src/test/java/tech/picnic/jolo/LoaderTest.java +++ b/src/test/java/tech/picnic/jolo/LoaderTest.java @@ -1,5 +1,6 @@ package tech.picnic.jolo; +import static com.google.common.collect.ImmutableList.toImmutableList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static tech.picnic.jolo.TestUtil.createRecord; @@ -245,7 +246,7 @@ public void testZeroOrOneToManyRecursiveReference() { expectedBar1.setOtherBar(Optional.of(expectedBar2)); expectedBar2.setOtherBar(Optional.of(expectedBar2)); - assertEquals(ImmutableList.of(expectedBar1, expectedBar2), l.getList()); + assertEquals(ImmutableList.of(expectedBar1, expectedBar2), l.collect(toImmutableList())); } @Test