diff --git a/helper/src/main/java/me/lucko/helper/bucket/AbstractBucket.java b/helper/src/main/java/me/lucko/helper/bucket/AbstractBucket.java index 4f5d544d..b96c63f1 100644 --- a/helper/src/main/java/me/lucko/helper/bucket/AbstractBucket.java +++ b/helper/src/main/java/me/lucko/helper/bucket/AbstractBucket.java @@ -28,7 +28,6 @@ import com.google.common.collect.ImmutableList; import me.lucko.helper.bucket.partitioning.PartitioningStrategy; -import me.lucko.helper.utils.ImmutableCollectors; import java.util.AbstractSet; import java.util.Collection; @@ -82,14 +81,19 @@ protected AbstractBucket(int size, PartitioningStrategy strategy) { this.size = size; this.content = createSet(); - //noinspection unchecked - Set[] objs = new Set[size]; + ImmutableList.Builder> sets = ImmutableList.builder(); + ImmutableList.Builder> views = ImmutableList.builder(); + for (int i = 0; i < size; i++) { - objs[i] = createSet(); + Set set = createSet(); + sets.add(set); + + SetView view = new SetView(set, i); + views.add(view); } - this.partitions = ImmutableList.copyOf(objs); - this.partitionView = this.partitions.stream().map(SetView::new).collect(ImmutableCollectors.toList()); + this.partitions = sets.build(); + this.partitionView = views.build(); this.partitionCycle = Cycle.of(this.partitionView); } @@ -235,9 +239,9 @@ private final class SetView extends AbstractSet implements BucketPartition private final Set backing; private final int index; - private SetView(Set backing) { + private SetView(Set backing, int index) { this.backing = backing; - this.index = AbstractBucket.this.partitions.indexOf(backing); + this.index = index; } @Override