From 4581deee469d0665c8fee0e93284b53d11ea24f4 Mon Sep 17 00:00:00 2001 From: Glavo Date: Wed, 10 Jul 2024 19:07:34 +0800 Subject: [PATCH] Delete Collection.fill(int, Supplier) --- .../java/kala/benchmark/TreeSeqBenchmark.java | 2 +- .../java/kala/collection/base/Iterators.java | 11 -------- .../collection/factory/CollectionFactory.java | 13 ---------- .../main/java/kala/collection/ArraySeq.java | 13 ---------- .../src/main/java/kala/collection/Seq.java | 4 --- .../collection/immutable/ImmutableArray.java | 17 ------------- .../immutable/ImmutableCollection.java | 4 --- .../immutable/ImmutableLinkedSeq.java | 16 ------------ .../collection/immutable/ImmutableSeq.java | 14 ----------- .../collection/immutable/ImmutableSeqs.java | 5 ---- .../immutable/ImmutableTreeSeq.java | 11 -------- .../collection/immutable/ImmutableVector.java | 25 ------------------- .../kala/collection/mutable/MutableArray.java | 17 ------------- .../collection/mutable/MutableArrayDeque.java | 12 --------- .../collection/mutable/MutableArrayList.java | 17 ------------- .../collection/mutable/MutableLinkedList.java | 8 ------ .../kala/collection/mutable/MutableList.java | 4 --- .../kala/collection/mutable/MutableSeq.java | 4 --- .../mutable/MutableSinglyLinkedList.java | 8 ------ .../mutable/MutableSmartArrayList.java | 15 ----------- .../kala/collection/base/IteratorsTest.java | 19 ++++++++++++-- .../immutable/ImmutableVectorTest.java | 8 ++---- .../collection/CollectionTestTemplate.java | 11 +++----- .../kala/collection/SeqTestTemplate.java | 5 ---- 24 files changed, 24 insertions(+), 239 deletions(-) diff --git a/benchmark/src/main/java/kala/benchmark/TreeSeqBenchmark.java b/benchmark/src/main/java/kala/benchmark/TreeSeqBenchmark.java index 4cbcb43d..be5c6891 100644 --- a/benchmark/src/main/java/kala/benchmark/TreeSeqBenchmark.java +++ b/benchmark/src/main/java/kala/benchmark/TreeSeqBenchmark.java @@ -42,7 +42,7 @@ public class TreeSeqBenchmark { @Setup public void setup() { Random random = new Random(0); - array = ImmutableArray.fill(length, () -> random.nextInt()); + array = ImmutableArray.fill(length, i -> random.nextInt()); vector = array.collect(ImmutableVector.factory()); treeSeq = array.collect(ImmutableTreeSeq.factory()); } diff --git a/kala-base/src/main/java/kala/collection/base/Iterators.java b/kala-base/src/main/java/kala/collection/base/Iterators.java index 2a55572d..ffac2954 100644 --- a/kala-base/src/main/java/kala/collection/base/Iterators.java +++ b/kala-base/src/main/java/kala/collection/base/Iterators.java @@ -131,17 +131,6 @@ public String toString() { return new Copies<>(n, value); } - public static @NotNull Iterator fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - if (n == 1) { - return of(supplier.get()); - } - Objects.requireNonNull(supplier); - return new FillSupplier<>(n, supplier); - } - public static @NotNull Iterator fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); diff --git a/kala-base/src/main/java/kala/collection/factory/CollectionFactory.java b/kala-base/src/main/java/kala/collection/factory/CollectionFactory.java index 5f568459..45ed1bc7 100644 --- a/kala-base/src/main/java/kala/collection/factory/CollectionFactory.java +++ b/kala-base/src/main/java/kala/collection/factory/CollectionFactory.java @@ -231,19 +231,6 @@ default R fill(int n, E value) { return build(builder); } - default R fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - - Builder builder = newBuilder(); - sizeHint(builder, n); - for (int i = 0; i < n; i++) { - addToBuilder(builder, supplier.get()); - } - return build(builder); - } - default R fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); diff --git a/kala-collection/src/main/java/kala/collection/ArraySeq.java b/kala-collection/src/main/java/kala/collection/ArraySeq.java index d8f48c4f..dae7747f 100644 --- a/kala-collection/src/main/java/kala/collection/ArraySeq.java +++ b/kala-collection/src/main/java/kala/collection/ArraySeq.java @@ -179,14 +179,6 @@ public static ArraySeq narrow(ArraySeq seq) { return new ArraySeq<>(ObjectArrays.fill(n, value)); } - public static @NotNull ArraySeq fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - - return new ArraySeq<>(ObjectArrays.fill(n, supplier)); - } - public static @NotNull ArraySeq fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); @@ -1202,11 +1194,6 @@ public ArraySeq fill(int n, E value) { return ArraySeq.fill(n, value); } - @Override - public ArraySeq fill(int n, @NotNull Supplier supplier) { - return ArraySeq.fill(n, supplier); - } - @Override public ArraySeq fill(int n, @NotNull IntFunction init) { return ArraySeq.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/Seq.java b/kala-collection/src/main/java/kala/collection/Seq.java index d340a927..d1a1b2cc 100644 --- a/kala-collection/src/main/java/kala/collection/Seq.java +++ b/kala-collection/src/main/java/kala/collection/Seq.java @@ -88,10 +88,6 @@ static Seq narrow(Seq seq) { return ImmutableSeq.fill(n, value); } - static @NotNull Seq fill(int n, @NotNull Supplier supplier) { - return ImmutableSeq.fill(n, supplier); - } - static @NotNull Seq fill(int n, @NotNull IntFunction init) { return ImmutableSeq.fill(n, init); } diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableArray.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableArray.java index d833514e..1dc930a9 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableArray.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableArray.java @@ -174,18 +174,6 @@ public static ImmutableArray narrow(ImmutableArray array) { return new ImmutableArray<>(ans); } - public static @NotNull ImmutableArray fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - - Object[] ans = new Object[n]; - for (int i = 0; i < n; i++) { - ans[i] = supplier.get(); - } - return new ImmutableArray<>(ans); - } - public static @NotNull ImmutableArray fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); @@ -319,11 +307,6 @@ public ImmutableArray fill(int n, E value) { return ImmutableArray.fill(n, value); } - @Override - public ImmutableArray fill(int n, @NotNull Supplier supplier) { - return ImmutableArray.fill(n, supplier); - } - @Override public ImmutableArray fill(int n, @NotNull IntFunction init) { return ImmutableArray.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableCollection.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableCollection.java index 6301b539..bf920697 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableCollection.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableCollection.java @@ -83,10 +83,6 @@ static ImmutableCollection narrow(ImmutableCollection collec return ImmutableSeq.fill(n, value); } - static @NotNull ImmutableCollection fill(int n, @NotNull Supplier supplier) { - return ImmutableSeq.fill(n, supplier); - } - static @NotNull ImmutableCollection fill(int n, @NotNull IntFunction init) { return ImmutableSeq.fill(n, init); } diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableLinkedSeq.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableLinkedSeq.java index 626bc0d0..b0849028 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableLinkedSeq.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableLinkedSeq.java @@ -150,22 +150,6 @@ public static ImmutableLinkedSeq empty() { return new ImmutableLinkedSeq<>(res, n); } - public static @NotNull ImmutableLinkedSeq fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - final Node res = new Node<>(supplier.get()); - Node t = res; - - for (int i = 1; i < n; i++) { - Node nl = new Node<>(supplier.get()); - t.tail = nl; - t = nl; - } - t.tail = nilNode(); - return new ImmutableLinkedSeq<>(res, n); - } - public static @NotNull ImmutableLinkedSeq fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeq.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeq.java index d5eccac0..29ddba0b 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeq.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeq.java @@ -180,20 +180,6 @@ static ImmutableSeq narrow(ImmutableSeq seq) { return new ImmutableSeqs.CopiesSeq<>(n, value); } - static @NotNull ImmutableSeq fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return ImmutableSeq.empty(); - } - return switch (n) { - case 1 -> ImmutableSeq.of(supplier.get()); - case 2 -> ImmutableSeq.of(supplier.get(), supplier.get()); - case 3 -> ImmutableSeq.of(supplier.get(), supplier.get(), supplier.get()); - case 4 -> ImmutableSeq.of(supplier.get(), supplier.get(), supplier.get(), supplier.get()); - case 5 -> ImmutableSeq.of(supplier.get(), supplier.get(), supplier.get(), supplier.get(), supplier.get()); - default -> ImmutableVector.fill(n, supplier); - }; - } - static @NotNull ImmutableSeq fill(int n, @NotNull IntFunction init) { if (n <= 0) { return ImmutableSeq.empty(); diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeqs.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeqs.java index 1c8418d6..4fffc5fb 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeqs.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableSeqs.java @@ -1227,11 +1227,6 @@ public ImmutableSeq fill(int n, E value) { return ImmutableSeq.fill(n, value); } - @Override - public ImmutableSeq fill(int n, @NotNull Supplier supplier) { - return ImmutableSeq.fill(n, supplier); - } - @Override public ImmutableSeq fill(int n, @NotNull IntFunction init) { return ImmutableSeq.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableTreeSeq.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableTreeSeq.java index 0f24b3e5..05c90dc9 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableTreeSeq.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableTreeSeq.java @@ -168,17 +168,6 @@ public static ImmutableTreeSeq empty() { return new ImmutableTreeSeq<>(node); } - public static @NotNull ImmutableTreeSeq fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - IndexedTree node = IndexedTree.empty(); - for (int i = 0; i < n; i++) { - node = node.plus(i, supplier.get()); - } - return new ImmutableTreeSeq<>(node); - } - public static @NotNull ImmutableTreeSeq fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); diff --git a/kala-collection/src/main/java/kala/collection/immutable/ImmutableVector.java b/kala-collection/src/main/java/kala/collection/immutable/ImmutableVector.java index 742861a4..698adb78 100644 --- a/kala-collection/src/main/java/kala/collection/immutable/ImmutableVector.java +++ b/kala-collection/src/main/java/kala/collection/immutable/ImmutableVector.java @@ -186,26 +186,6 @@ static ImmutableVector narrow(ImmutableVector vector) { return builder.build(); } - public static @NotNull ImmutableVector fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - - if (n <= ImmutableVectors.WIDTH) { - Object[] arr = new Object[n]; - for (int i = 0; i < n; i++) { - arr[i] = supplier.get(); - } - return new ImmutableVectors.Vector1<>(arr); - } - - ImmutableVectors.VectorBuilder builder = new ImmutableVectors.VectorBuilder<>(); - while (n-- > 0) { - builder.add(supplier.get()); - } - return builder.build(); - } - public static @NotNull ImmutableVector fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); @@ -596,11 +576,6 @@ public ImmutableVector fill(int n, E value) { return ImmutableVector.fill(n, value); } - @Override - public ImmutableVector fill(int n, @NotNull Supplier supplier) { - return ImmutableVector.fill(n, supplier); - } - @Override public ImmutableVector fill(int n, @NotNull IntFunction init) { return ImmutableVector.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableArray.java b/kala-collection/src/main/java/kala/collection/mutable/MutableArray.java index aa42f1be..a71e82d3 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableArray.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableArray.java @@ -165,18 +165,6 @@ private MutableArray(Object @NotNull [] array) { return new MutableArray<>(ans); } - public static @NotNull MutableArray fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return empty(); - } - - Object[] ans = new Object[n]; - for (int i = 0; i < n; i++) { - ans[i] = supplier.get(); - } - return new MutableArray<>(ans); - } - public static @NotNull MutableArray fill(int n, @NotNull IntFunction init) { if (n <= 0) { return empty(); @@ -317,11 +305,6 @@ public MutableArray fill(int n, E value) { return MutableArray.fill(n, value); } - @Override - public MutableArray fill(int n, @NotNull Supplier supplier) { - return MutableArray.fill(n, supplier); - } - @Override public MutableArray fill(int n, @NotNull IntFunction init) { return MutableArray.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableArrayDeque.java b/kala-collection/src/main/java/kala/collection/mutable/MutableArrayDeque.java index a6ccd8d8..0e08c061 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableArrayDeque.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableArrayDeque.java @@ -217,18 +217,6 @@ public static MutableArrayDeque create(int initialCapacity) { return new MutableArrayDeque<>(arr, 0, n); } - public static @NotNull MutableArrayDeque fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return new MutableArrayDeque<>(); - } - - Object[] arr = new Object[Integer.max(DEFAULT_CAPACITY, n)]; - for (int i = 0; i < n; i++) { - arr[i] = supplier.get(); - } - return new MutableArrayDeque<>(arr, 0, n); - } - public static @NotNull MutableArrayDeque fill(int n, @NotNull IntFunction init) { if (n <= 0) { return new MutableArrayDeque<>(); diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableArrayList.java b/kala-collection/src/main/java/kala/collection/mutable/MutableArrayList.java index a654a6e3..9d17d8c0 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableArrayList.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableArrayList.java @@ -185,18 +185,6 @@ public MutableArrayList(int initialCapacity) { return new MutableArrayList<>(arr, n); } - public static @NotNull MutableArrayList fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return new MutableArrayList<>(); - } - - Object[] arr = new Object[Integer.max(DEFAULT_CAPACITY, n)]; - for (int i = 0; i < n; i++) { - arr[i] = supplier.get(); - } - return new MutableArrayList<>(arr, n); - } - public static @NotNull MutableArrayList fill(int n, @NotNull IntFunction init) { if (n <= 0) { return new MutableArrayList<>(); @@ -726,11 +714,6 @@ public MutableArrayList fill(int n, E value) { return MutableArrayList.fill(n, value); } - @Override - public MutableArrayList fill(int n, @NotNull Supplier supplier) { - return MutableArrayList.fill(n, supplier); - } - @Override public MutableArrayList fill(int n, @NotNull IntFunction init) { return MutableArrayList.fill(n, init); diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableLinkedList.java b/kala-collection/src/main/java/kala/collection/mutable/MutableLinkedList.java index 236f86c4..12f66087 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableLinkedList.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableLinkedList.java @@ -153,14 +153,6 @@ public MutableLinkedList() { return res; } - public static @NotNull MutableLinkedList fill(int n, @NotNull Supplier supplier) { - MutableLinkedList res = new MutableLinkedList<>(); - for (int i = 0; i < n; i++) { - res.append(supplier.get()); - } - return res; - } - public static @NotNull MutableLinkedList fill(int n, @NotNull IntFunction init) { MutableLinkedList res = new MutableLinkedList<>(); for (int i = 0; i < n; i++) { diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableList.java b/kala-collection/src/main/java/kala/collection/mutable/MutableList.java index 62f08916..1ef82df9 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableList.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableList.java @@ -98,10 +98,6 @@ public interface MutableList extends MutableSeq, Growable { return MutableArrayList.fill(n, value); } - static @NotNull MutableList fill(int n, @NotNull Supplier supplier) { - return MutableArrayList.fill(n, supplier); - } - static @NotNull MutableList fill(int n, @NotNull IntFunction init) { return MutableArrayList.fill(n, init); } diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableSeq.java b/kala-collection/src/main/java/kala/collection/mutable/MutableSeq.java index 40ca4a82..c1f1fa74 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableSeq.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableSeq.java @@ -98,10 +98,6 @@ public interface MutableSeq extends MutableCollection, Seq, MutableAnyS return MutableArray.fill(n, value); } - static @NotNull MutableSeq fill(int n, @NotNull Supplier supplier) { - return MutableArray.fill(n, supplier); - } - static @NotNull MutableSeq fill(int n, @NotNull IntFunction init) { return MutableArray.fill(n, init); } diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableSinglyLinkedList.java b/kala-collection/src/main/java/kala/collection/mutable/MutableSinglyLinkedList.java index 580cc209..b8e7fc50 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableSinglyLinkedList.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableSinglyLinkedList.java @@ -127,14 +127,6 @@ public final class MutableSinglyLinkedList extends ImmutableLinkedSeq.Builder return res; } - public static @NotNull MutableSinglyLinkedList fill(int n, @NotNull Supplier supplier) { - MutableSinglyLinkedList res = new MutableSinglyLinkedList<>(); - while (n-- > 0) { - res.append(supplier.get()); - } - return res; - } - public static @NotNull MutableSinglyLinkedList fill(int n, @NotNull IntFunction init) { MutableSinglyLinkedList res = new MutableSinglyLinkedList<>(); for (int i = 0; i < n; i++) { diff --git a/kala-collection/src/main/java/kala/collection/mutable/MutableSmartArrayList.java b/kala-collection/src/main/java/kala/collection/mutable/MutableSmartArrayList.java index 82b2edeb..f3558250 100644 --- a/kala-collection/src/main/java/kala/collection/mutable/MutableSmartArrayList.java +++ b/kala-collection/src/main/java/kala/collection/mutable/MutableSmartArrayList.java @@ -160,21 +160,6 @@ public MutableSmartArrayList() { return new MutableSmartArrayList<>(n, arr); } - public static @NotNull MutableSmartArrayList fill(int n, @NotNull Supplier supplier) { - if (n <= 0) { - return new MutableSmartArrayList<>(); - } - if (n == 1) { - return MutableSmartArrayList.of(supplier.get()); - } - - Object[] arr = new Object[Integer.max(DEFAULT_CAPACITY, n)]; - for (int i = 0; i < n; i++) { - arr[i] = supplier.get(); - } - return new MutableSmartArrayList<>(n, arr); - } - public static @NotNull MutableSmartArrayList fill(int n, @NotNull IntFunction init) { if (n <= 0) { return new MutableSmartArrayList<>(); diff --git a/src/test/java/kala/collection/base/IteratorsTest.java b/src/test/java/kala/collection/base/IteratorsTest.java index 522855d6..4adb18c9 100644 --- a/src/test/java/kala/collection/base/IteratorsTest.java +++ b/src/test/java/kala/collection/base/IteratorsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024 Glavo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package kala.collection.base; import kala.tuple.Tuple2; @@ -43,11 +58,11 @@ public void fillTest() { assertIteratorElements(Iterators.fill(2, "foo"), "foo", "foo"); assertIteratorElements(Iterators.fill(10, "foo"), ObjectArrays.fill(10, "foo")); - class TestAdder implements Supplier { + class TestAdder implements IntFunction { private int i = 0; @Override - public Integer get() { + public Integer apply(int value) { return i++; } } diff --git a/src/test/java/kala/collection/immutable/ImmutableVectorTest.java b/src/test/java/kala/collection/immutable/ImmutableVectorTest.java index e2a50f53..c9a66cae 100644 --- a/src/test/java/kala/collection/immutable/ImmutableVectorTest.java +++ b/src/test/java/kala/collection/immutable/ImmutableVectorTest.java @@ -58,16 +58,12 @@ public void fillTest() { v = ImmutableVector.fill(ImmutableVectors.WIDTH, "str"); assertSame(ImmutableVectors.Vector1.class, v.getClass()); - v = ImmutableVector.fill(ImmutableVectors.WIDTH, () -> "str"); - assertSame(ImmutableVectors.Vector1.class, v.getClass()); - v = ImmutableVector.fill(ImmutableVectors.WIDTH, (i) -> "str"); + v = ImmutableVector.fill(ImmutableVectors.WIDTH, i -> "str"); assertSame(ImmutableVectors.Vector1.class, v.getClass()); v = ImmutableVector.fill(ImmutableVectors.WIDTH + 1, "str"); assertSame(ImmutableVectors.Vector2.class, v.getClass()); - v = ImmutableVector.fill(ImmutableVectors.WIDTH + 1, () -> "str"); - assertSame(ImmutableVectors.Vector2.class, v.getClass()); - v = ImmutableVector.fill(ImmutableVectors.WIDTH + 1, (i) -> "str"); + v = ImmutableVector.fill(ImmutableVectors.WIDTH + 1, i -> "str"); assertSame(ImmutableVectors.Vector2.class, v.getClass()); } diff --git a/src/test/template/kala/collection/CollectionTestTemplate.java b/src/test/template/kala/collection/CollectionTestTemplate.java index 75bc1c4d..6187b2e0 100644 --- a/src/test/template/kala/collection/CollectionTestTemplate.java +++ b/src/test/template/kala/collection/CollectionTestTemplate.java @@ -10,6 +10,7 @@ import java.io.*; import java.util.Arrays; import java.util.List; +import java.util.function.IntFunction; import java.util.function.Supplier; import static org.junit.jupiter.api.Assertions.*; @@ -75,10 +76,6 @@ default void factoryTest() { assertIterableEquals(List.of(), factory.fill(-1, "foo")); assertIterableEquals(List.of(), factory.fill(Integer.MIN_VALUE, "foo")); - assertIterableEquals(List.of(), factory.fill(0, () -> "foo")); - assertIterableEquals(List.of(), factory.fill(-1, () -> "foo")); - assertIterableEquals(List.of(), factory.fill(Integer.MIN_VALUE, () -> "foo")); - assertIterableEquals(List.of(), factory.fill(0, i -> "foo")); assertIterableEquals(List.of(), factory.fill(-1, i -> "foo")); assertIterableEquals(List.of(), factory.fill(Integer.MIN_VALUE, i -> "foo")); @@ -88,13 +85,13 @@ default void factoryTest() { assertIterableEquals(List.of("foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo", "foo"), factory.fill(10, "foo")); - assertIterableEquals(List.of("foo"), factory.fill(1, () -> "foo")); + assertIterableEquals(List.of("foo"), factory.fill(1, i -> "foo")); assertIterableEquals(List.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), - factory.fill(10, new Supplier<>() { + factory.fill(10, new IntFunction<>() { int i = 0; @Override - public Object get() { + public Object apply(int value) { return i++; } }) diff --git a/src/test/template/kala/collection/SeqTestTemplate.java b/src/test/template/kala/collection/SeqTestTemplate.java index 3ad5c18c..01207b4a 100644 --- a/src/test/template/kala/collection/SeqTestTemplate.java +++ b/src/test/template/kala/collection/SeqTestTemplate.java @@ -132,7 +132,6 @@ default void fillTest() { final MethodHandles.Lookup lookup = MethodHandles.publicLookup(); final MethodHandle fillValue = lookup.findStatic(klass, "fill", MethodType.methodType(klass, int.class, Object.class)); - final MethodHandle fillSupplier = lookup.findStatic(klass, "fill", MethodType.methodType(klass, int.class, Supplier.class)); final MethodHandle fillIntFunction = lookup.findStatic(klass, "fill", MethodType.methodType(klass, int.class, IntFunction.class)); assertIterableEquals(List.of(), (Seq) fillValue.invoke(0, "value")); @@ -140,17 +139,13 @@ default void fillTest() { assertIterableEquals(List.of("value", "value", "value"), (Seq) fillValue.invoke(3, "value")); assertIterableEquals(List.of("value0"), (Seq) fillIntFunction.invoke(1, (IntFunction) i -> "value" + i)); - assertIterableEquals(List.of("value"), (Seq) fillSupplier.invoke(1, (Supplier) () -> "value")); List expected = List.of(0, 1, 2, 3, 4, 5); IntVar intVar = new IntVar(); - Supplier supplier = () -> intVar.value++; IntFunction function = i -> i; - assertIterableEquals(List.of(), (Seq) fillSupplier.invoke(0, supplier)); assertIterableEquals(List.of(), (Seq) fillIntFunction.invoke(0, function)); - assertIterableEquals(expected, (Seq) fillSupplier.invoke(6, supplier)); assertIterableEquals(expected, (Seq) fillIntFunction.invoke(6, function)); } catch (Throwable e) { fail(e);