From 22697675e700acf85bf250f2f3be40f3adc17497 Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 11 Sep 2023 08:20:03 +0200 Subject: [PATCH 1/4] moved content of PullBasedSpliteratorTest to kotlin --- .../commons/PullBasedSpliteratorTest.kt | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt diff --git a/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt new file mode 100644 index 00000000..78eb35ad --- /dev/null +++ b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt @@ -0,0 +1,58 @@ +/* + * Made with all the love in the world + * by scireum in Remshalden, Germany + * + * Copyright by scireum GmbH + * http://www.scireum.de - info@scireum.de + */ + +package sirius.kernel.commons; + +import org.junit.jupiter.api.Test; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PullBasedSpliteratorTest { + + private static class TestSpliterator extends PullBasedSpliterator { + + private int index; + + @Nullable + @Override + protected Iterator pullNextBlock() { + if (index < 10) { + List result = new ArrayList<>(); + for (int i = index; i < index + 5; i++) { + result.add(i); + } + index += 5; + + return result.iterator(); + } + + return Collections.emptyIterator(); + } + + @Override + public int characteristics() { + return 0; + } + } + + @Test + void streamWorksProperly() { + assertEquals(10, StreamSupport.stream(new TestSpliterator(), false).count()); + assertEquals(StreamSupport.stream(new TestSpliterator(), false).collect(Collectors.toList()), + Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList())); + } +} From 274fb85b3a30b2bbd1c74ae6539a71f288109796 Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 11 Sep 2023 08:21:45 +0200 Subject: [PATCH 2/4] Converted code to kotlin --- .../commons/PullBasedSpliteratorTest.kt | 69 ++++++++----------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt index 78eb35ad..c383f229 100644 --- a/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt +++ b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt @@ -5,54 +5,41 @@ * Copyright by scireum GmbH * http://www.scireum.de - info@scireum.de */ - -package sirius.kernel.commons; - -import org.junit.jupiter.api.Test; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class PullBasedSpliteratorTest { - - private static class TestSpliterator extends PullBasedSpliterator { - - private int index; - - @Nullable - @Override - protected Iterator pullNextBlock() { +package sirius.kernel.commons + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import java.util.* +import java.util.stream.Collectors +import java.util.stream.Stream +import java.util.stream.StreamSupport + +internal class PullBasedSpliteratorTest { + private class TestSpliterator : PullBasedSpliterator() { + private var index = 0 + override fun pullNextBlock(): Iterator? { if (index < 10) { - List result = new ArrayList<>(); - for (int i = index; i < index + 5; i++) { - result.add(i); + val result: MutableList = ArrayList() + for (i in index until index + 5) { + result.add(i) } - index += 5; - - return result.iterator(); + index += 5 + return result.iterator() } - - return Collections.emptyIterator(); + return Collections.emptyIterator() } - @Override - public int characteristics() { - return 0; + override fun characteristics(): Int { + return 0 } } @Test - void streamWorksProperly() { - assertEquals(10, StreamSupport.stream(new TestSpliterator(), false).count()); - assertEquals(StreamSupport.stream(new TestSpliterator(), false).collect(Collectors.toList()), - Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList())); + fun streamWorksProperly() { + Assertions.assertEquals(10, StreamSupport.stream(TestSpliterator(), false).count()) + Assertions.assertEquals( + StreamSupport.stream(TestSpliterator(), false).collect(Collectors.toList()), + Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList()) + ) } -} +} \ No newline at end of file From 843823067a96036df398fd1c03b4db092585c118 Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 11 Sep 2023 08:22:02 +0200 Subject: [PATCH 3/4] Deleted PullBasedSpliteratorTest.java --- .../commons/PullBasedSpliteratorTest.java | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java diff --git a/src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java b/src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java deleted file mode 100644 index d0dd6bf1..00000000 --- a/src/test/java/sirius/kernel/commons/PullBasedSpliteratorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Made with all the love in the world - * by scireum in Remshalden, Germany - * - * Copyright by scireum GmbH - * http://www.scireum.de - info@scireum.de - */ - -package sirius.kernel.commons; - -import org.junit.jupiter.api.Test; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class PullBasedSpliteratorTest { - - private static class TestSpliterator extends PullBasedSpliterator { - - private int index; - - @Nullable - @Override - protected Iterator pullNextBlock() { - if (index < 10) { - List result = new ArrayList<>(); - for (int i = index; i < index + 5; i++) { - result.add(i); - } - index += 5; - - return result.iterator(); - } - - return Collections.emptyIterator(); - } - - @Override - public int characteristics() { - return 0; - } - } - - @Test - void streamWorksProperly() { - assertEquals(10, StreamSupport.stream(new TestSpliterator(), false).count()); - assertEquals(StreamSupport.stream(new TestSpliterator(), false).collect(Collectors.toList()), - Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList())); - } -} From e609efcf8c8d2250ab4add5ed2f48d5f2f45fb1c Mon Sep 17 00:00:00 2001 From: MOOOOOSER Date: Mon, 11 Sep 2023 08:23:36 +0200 Subject: [PATCH 4/4] Some formatting --- .../kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt index c383f229..b2ec666c 100644 --- a/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt +++ b/src/test/kotlin/sirius/kernel/commons/PullBasedSpliteratorTest.kt @@ -42,4 +42,4 @@ internal class PullBasedSpliteratorTest { Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).collect(Collectors.toList()) ) } -} \ No newline at end of file +}