Skip to content

Commit

Permalink
Delete Collection.fill(int, Supplier<T>)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jul 10, 2024
1 parent ed4c524 commit 4581dee
Show file tree
Hide file tree
Showing 24 changed files with 24 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
11 changes: 0 additions & 11 deletions kala-base/src/main/java/kala/collection/base/Iterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@ public String toString() {
return new Copies<>(n, value);
}

public static <E> @NotNull Iterator<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
if (n <= 0) {
return empty();
}
if (n == 1) {
return of(supplier.get());
}
Objects.requireNonNull(supplier);
return new FillSupplier<>(n, supplier);
}

public static <E> @NotNull Iterator<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,6 @@ default R fill(int n, E value) {
return build(builder);
}

default R fill(int n, @NotNull Supplier<? extends E> 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<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down
13 changes: 0 additions & 13 deletions kala-collection/src/main/java/kala/collection/ArraySeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ public static <E> ArraySeq<E> narrow(ArraySeq<? extends E> seq) {
return new ArraySeq<>(ObjectArrays.fill(n, value));
}

public static <E> @NotNull ArraySeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
if (n <= 0) {
return empty();
}

return new ArraySeq<>(ObjectArrays.fill(n, supplier));
}

public static <E> @NotNull ArraySeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down Expand Up @@ -1202,11 +1194,6 @@ public ArraySeq<E> fill(int n, E value) {
return ArraySeq.fill(n, value);
}

@Override
public ArraySeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ArraySeq.fill(n, supplier);
}

@Override
public ArraySeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ArraySeq.fill(n, init);
Expand Down
4 changes: 0 additions & 4 deletions kala-collection/src/main/java/kala/collection/Seq.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ static <E> Seq<E> narrow(Seq<? extends E> seq) {
return ImmutableSeq.fill(n, value);
}

static <E> @NotNull Seq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ImmutableSeq.fill(n, supplier);
}

static <E> @NotNull Seq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ImmutableSeq.fill(n, init);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ public static <E> ImmutableArray<E> narrow(ImmutableArray<? extends E> array) {
return new ImmutableArray<>(ans);
}

public static <E> @NotNull ImmutableArray<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull ImmutableArray<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down Expand Up @@ -319,11 +307,6 @@ public ImmutableArray<E> fill(int n, E value) {
return ImmutableArray.fill(n, value);
}

@Override
public ImmutableArray<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ImmutableArray.fill(n, supplier);
}

@Override
public ImmutableArray<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ImmutableArray.fill(n, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ static <E> ImmutableCollection<E> narrow(ImmutableCollection<? extends E> collec
return ImmutableSeq.fill(n, value);
}

static <E> @NotNull ImmutableCollection<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ImmutableSeq.fill(n, supplier);
}

static <E> @NotNull ImmutableCollection<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ImmutableSeq.fill(n, init);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,6 @@ public static <E> ImmutableLinkedSeq<E> empty() {
return new ImmutableLinkedSeq<>(res, n);
}

public static <E> @NotNull ImmutableLinkedSeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
if (n <= 0) {
return empty();
}
final Node<E> res = new Node<>(supplier.get());
Node<E> t = res;

for (int i = 1; i < n; i++) {
Node<E> nl = new Node<>(supplier.get());
t.tail = nl;
t = nl;
}
t.tail = nilNode();
return new ImmutableLinkedSeq<>(res, n);
}

public static <E> @NotNull ImmutableLinkedSeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,6 @@ static <E> ImmutableSeq<E> narrow(ImmutableSeq<? extends E> seq) {
return new ImmutableSeqs.CopiesSeq<>(n, value);
}

static <E> @NotNull ImmutableSeq<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull ImmutableSeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return ImmutableSeq.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,6 @@ public ImmutableSeq<E> fill(int n, E value) {
return ImmutableSeq.fill(n, value);
}

@Override
public ImmutableSeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ImmutableSeq.fill(n, supplier);
}

@Override
public ImmutableSeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ImmutableSeq.fill(n, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,6 @@ public static <E> ImmutableTreeSeq<E> empty() {
return new ImmutableTreeSeq<>(node);
}

public static <E> @NotNull ImmutableTreeSeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
if (n <= 0) {
return empty();
}
IndexedTree<E> node = IndexedTree.empty();
for (int i = 0; i < n; i++) {
node = node.plus(i, supplier.get());
}
return new ImmutableTreeSeq<>(node);
}

public static <E> @NotNull ImmutableTreeSeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,6 @@ static <E> ImmutableVector<E> narrow(ImmutableVector<? extends E> vector) {
return builder.build();
}

public static <E> @NotNull ImmutableVector<E> fill(int n, @NotNull Supplier<? extends E> 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<E> builder = new ImmutableVectors.VectorBuilder<>();
while (n-- > 0) {
builder.add(supplier.get());
}
return builder.build();
}

public static <E> @NotNull ImmutableVector<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down Expand Up @@ -596,11 +576,6 @@ public ImmutableVector<E> fill(int n, E value) {
return ImmutableVector.fill(n, value);
}

@Override
public ImmutableVector<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return ImmutableVector.fill(n, supplier);
}

@Override
public ImmutableVector<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return ImmutableVector.fill(n, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,6 @@ private MutableArray(Object @NotNull [] array) {
return new MutableArray<>(ans);
}

public static <E> @NotNull MutableArray<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull MutableArray<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return empty();
Expand Down Expand Up @@ -317,11 +305,6 @@ public MutableArray<E> fill(int n, E value) {
return MutableArray.fill(n, value);
}

@Override
public MutableArray<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return MutableArray.fill(n, supplier);
}

@Override
public MutableArray<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return MutableArray.fill(n, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,6 @@ public static <E> MutableArrayDeque<E> create(int initialCapacity) {
return new MutableArrayDeque<>(arr, 0, n);
}

public static <E> @NotNull MutableArrayDeque<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull MutableArrayDeque<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return new MutableArrayDeque<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,6 @@ public MutableArrayList(int initialCapacity) {
return new MutableArrayList<>(arr, n);
}

public static <E> @NotNull MutableArrayList<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull MutableArrayList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return new MutableArrayList<>();
Expand Down Expand Up @@ -726,11 +714,6 @@ public MutableArrayList<E> fill(int n, E value) {
return MutableArrayList.fill(n, value);
}

@Override
public MutableArrayList<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return MutableArrayList.fill(n, supplier);
}

@Override
public MutableArrayList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return MutableArrayList.fill(n, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@ public MutableLinkedList() {
return res;
}

public static <E> @NotNull MutableLinkedList<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
MutableLinkedList<E> res = new MutableLinkedList<>();
for (int i = 0; i < n; i++) {
res.append(supplier.get());
}
return res;
}

public static <E> @NotNull MutableLinkedList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
MutableLinkedList<E> res = new MutableLinkedList<>();
for (int i = 0; i < n; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public interface MutableList<E> extends MutableSeq<E>, Growable<E> {
return MutableArrayList.fill(n, value);
}

static <E> @NotNull MutableList<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return MutableArrayList.fill(n, supplier);
}

static <E> @NotNull MutableList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return MutableArrayList.fill(n, init);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public interface MutableSeq<E> extends MutableCollection<E>, Seq<E>, MutableAnyS
return MutableArray.fill(n, value);
}

static <E> @NotNull MutableSeq<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
return MutableArray.fill(n, supplier);
}

static <E> @NotNull MutableSeq<E> fill(int n, @NotNull IntFunction<? extends E> init) {
return MutableArray.fill(n, init);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ public final class MutableSinglyLinkedList<E> extends ImmutableLinkedSeq.Builder
return res;
}

public static <E> @NotNull MutableSinglyLinkedList<E> fill(int n, @NotNull Supplier<? extends E> supplier) {
MutableSinglyLinkedList<E> res = new MutableSinglyLinkedList<>();
while (n-- > 0) {
res.append(supplier.get());
}
return res;
}

public static <E> @NotNull MutableSinglyLinkedList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
MutableSinglyLinkedList<E> res = new MutableSinglyLinkedList<>();
for (int i = 0; i < n; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,6 @@ public MutableSmartArrayList() {
return new MutableSmartArrayList<>(n, arr);
}

public static <E> @NotNull MutableSmartArrayList<E> fill(int n, @NotNull Supplier<? extends E> 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 <E> @NotNull MutableSmartArrayList<E> fill(int n, @NotNull IntFunction<? extends E> init) {
if (n <= 0) {
return new MutableSmartArrayList<>();
Expand Down
Loading

0 comments on commit 4581dee

Please sign in to comment.