Skip to content

Commit

Permalink
Replace UnifiedSet.newSet(initialCapacity) with Sets.mutable.withInit…
Browse files Browse the repository at this point in the history
…ialCapacity().
  • Loading branch information
motlin committed Apr 14, 2022
1 parent 95fa9ab commit 6999ba9
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 34 deletions.
6 changes: 5 additions & 1 deletion .idea/inspectionProfiles/IDE.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -61,6 +61,7 @@
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.SortedSets;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.multimap.MutableMultimap;
Expand All @@ -71,7 +72,6 @@
import org.eclipse.collections.impl.Counter;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.bag.sorted.mutable.TreeBag;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;
import org.eclipse.collections.impl.utility.Iterate;

Expand Down Expand Up @@ -898,7 +898,7 @@ public MutableList<T> toSortedList(Comparator<? super T> comparator)
@Override
public MutableSet<T> toSet()
{
MutableSet<T> result = UnifiedSet.newSet(this.sizeDistinct());
MutableSet<T> result = Sets.mutable.withInitialCapacity(this.sizeDistinct());
this.forEachWithOccurrences((each, occurrences) -> result.add(each));
return result;
}
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.ordered.OrderedIterable;
Expand All @@ -39,7 +40,6 @@
import org.eclipse.collections.impl.list.fixed.ArrayAdapter;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.utility.ArrayIterate;
import org.eclipse.collections.impl.utility.Iterate;

Expand Down Expand Up @@ -508,7 +508,7 @@ public <S> ImmutableBag<Pair<T, S>> zip(Iterable<S> that)
@Deprecated
public ImmutableSet<Pair<T, Integer>> zipWithIndex()
{
return this.zipWithIndex(UnifiedSet.newSet(this.size())).toImmutable();
return this.zipWithIndex(Sets.mutable.withInitialCapacity(this.size())).toImmutable();
}

protected Object writeReplace()
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs and others.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -409,7 +409,7 @@ public <S> ImmutableSet<Pair<V, S>> zip(Iterable<S> that)
@Deprecated
public ImmutableSet<Pair<V, Integer>> zipWithIndex()
{
return this.delegate.zipWithIndex(UnifiedSet.newSet(this.size())).toImmutable();
return this.delegate.zipWithIndex(Sets.mutable.withInitialCapacity(this.size())).toImmutable();
}

@Override
Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.factory.BiMaps;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.multimap.set.MutableSetMultimap;
Expand Down Expand Up @@ -574,7 +575,7 @@ public <VV> MutableBag<VV> collectIf(Predicate<? super V> predicate, Function<?
@Deprecated
public MutableSet<Pair<V, Integer>> zipWithIndex()
{
return this.delegate.zipWithIndex(UnifiedSet.newSet(this.size()));
return this.delegate.zipWithIndex(Sets.mutable.withInitialCapacity(this.size()));
}

@Override
Expand Down Expand Up @@ -852,7 +853,7 @@ public String toString()

protected Object writeReplace()
{
MutableSet<K> replace = UnifiedSet.newSet(AbstractMutableBiMap.this.size());
MutableSet<K> replace = Sets.mutable.withInitialCapacity(AbstractMutableBiMap.this.size());
AbstractMutableBiMap.this.forEachKey(CollectionAddProcedure.on(replace));
return replace;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs and others.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -38,6 +38,7 @@
import org.eclipse.collections.api.block.procedure.primitive.IntProcedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.bag.mutable.HashBag;
Expand Down Expand Up @@ -934,7 +935,7 @@ public MutableList<Integer> toList()
@Override
public MutableSet<Integer> toSet()
{
MutableSet<Integer> set = UnifiedSet.newSet(this.size());
MutableSet<Integer> set = Sets.mutable.withInitialCapacity(this.size());
this.forEach(CollectionAddProcedure.on(set));
return set;
}
Expand Down
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.primitive.BooleanBags;
import org.eclipse.collections.api.factory.primitive.ByteBags;
import org.eclipse.collections.api.factory.primitive.CharBags;
Expand Down Expand Up @@ -84,7 +85,6 @@
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.partition.bag.PartitionHashBag;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.tuple.ImmutableEntry;
import org.eclipse.collections.impl.utility.MapIterate;

Expand Down Expand Up @@ -137,7 +137,7 @@ public ImmutableSetMultimap<V, K> flip()
@Override
public Set<Entry<K, V>> entrySet()
{
MutableSet<Entry<K, V>> set = UnifiedSet.newSet(this.size());
MutableSet<Entry<K, V>> set = Sets.mutable.withInitialCapacity(this.size());
this.forEachKeyValue((key, value) -> set.add(ImmutableEntry.of(key, value)));
return set.toImmutable().castToSet();
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public <S> ImmutableBag<Pair<V, S>> zip(Iterable<S> that)
@Deprecated
public ImmutableSet<Pair<V, Integer>> zipWithIndex()
{
return this.zipWithIndex(UnifiedSet.newSet(this.size())).toImmutable();
return this.zipWithIndex(Sets.mutable.withInitialCapacity(this.size())).toImmutable();
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs and others.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -17,6 +17,7 @@
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
Expand All @@ -29,7 +30,6 @@
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.multimap.AbstractSynchronizedPutMultimap;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.utility.ArrayIterate;
import org.eclipse.collections.impl.utility.Iterate;

Expand Down Expand Up @@ -95,7 +95,7 @@ public static <K, V> SynchronizedPutUnifiedSetMultimap<K, V> newMultimap(Iterabl
@Override
protected MutableSet<V> createCollection()
{
return UnifiedSet.newSet(1);
return Sets.mutable.withInitialCapacity(1);
}

@Override
Expand Down
Expand Up @@ -15,13 +15,13 @@
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.set.sorted.SortedSetIterable;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.list.mutable.CompositeFastList;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet;
import org.eclipse.collections.impl.utility.internal.DefaultSpeciesNewStrategy;

Expand Down Expand Up @@ -62,7 +62,7 @@ protected final Collection<T> initializeResult(
if (sourceCollection instanceof SetIterable)
{
this.setCombineOne(true);
return UnifiedSet.newSet(initialCapacity);
return Sets.mutable.withInitialCapacity(initialCapacity);
}
if (sourceCollection instanceof Bag || sourceCollection instanceof MapIterable)
{
Expand Down
Expand Up @@ -15,14 +15,14 @@
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.set.sorted.SortedSetIterable;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.list.mutable.CompositeFastList;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.utility.internal.DefaultSpeciesNewStrategy;

public abstract class AbstractTransformerBasedCombiner<V, T, BT extends Procedure<T>>
Expand Down Expand Up @@ -55,7 +55,7 @@ protected Collection<V> initializeResult(Iterable<T> sourceIterable, Collection<
if (sourceIterable instanceof SetIterable)
{
this.setCombineOne(true);
return UnifiedSet.newSet(initialCapacity);
return Sets.mutable.withInitialCapacity(initialCapacity);
}
if (sourceIterable instanceof Bag || sourceIterable instanceof MapIterable)
{
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.primitive.BooleanSets;
import org.eclipse.collections.api.factory.primitive.ByteSets;
import org.eclipse.collections.api.factory.primitive.CharSets;
Expand Down Expand Up @@ -345,7 +346,7 @@ public <S> MutableSet<Pair<T, S>> zip(Iterable<S> that)
@Deprecated
public MutableSet<Pair<T, Integer>> zipWithIndex()
{
return this.zipWithIndex(UnifiedSet.newSet(this.size()));
return this.zipWithIndex(Sets.mutable.withInitialCapacity(this.size()));
}

@Override
Expand Down
Expand Up @@ -202,7 +202,7 @@ public <P> PartitionImmutableSet<T> partitionWith(Predicate2<? super T, ? super
@Override
public <S> ImmutableSet<S> selectInstancesOf(Class<S> clazz)
{
MutableSet<S> result = UnifiedSet.newSet(this.size());
MutableSet<S> result = Sets.mutable.withInitialCapacity(this.size());
this.forEach(new SelectInstancesOfProcedure<>(clazz, result));
return result.toImmutable();
}
Expand Down Expand Up @@ -374,13 +374,13 @@ public <S> ImmutableSet<Pair<T, S>> zip(Iterable<S> that)
@Deprecated
public ImmutableSet<Pair<T, Integer>> zipWithIndex()
{
return this.zipWithIndex(UnifiedSet.newSet(this.size())).toImmutable();
return this.zipWithIndex(Sets.mutable.withInitialCapacity(this.size())).toImmutable();
}

@Override
protected MutableCollection<T> newMutable(int size)
{
return UnifiedSet.newSet(size);
return Sets.mutable.withInitialCapacity(size);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -15,10 +15,10 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;

class ImmutableSetSerializationProxy<T> implements Externalizable
{
Expand Down Expand Up @@ -65,7 +65,7 @@ public void safeValue(T value) throws IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
int size = in.readInt();
MutableSet<T> deserializedSet = UnifiedSet.newSet(size);
MutableSet<T> deserializedSet = Sets.mutable.withInitialCapacity(size);

for (int i = 0; i < size; i++)
{
Expand Down
Expand Up @@ -84,7 +84,7 @@ public MutableSet<T> newEmpty()

protected <K> MutableSet<K> newEmptySameSize()
{
return UnifiedSet.newSet(this.size());
return Sets.mutable.withInitialCapacity(this.size());
}

@Override
Expand Down
Expand Up @@ -29,6 +29,7 @@ public <T> MutableSet<T> empty()
@Override
public <T> MutableSet<T> withInitialCapacity(int capacity)
{
//noinspection SSBasedInspection
return UnifiedSet.newSet(capacity);
}

Expand Down
Expand Up @@ -381,7 +381,7 @@ public <S> MutableSet<Pair<T, S>> zip(Iterable<S> that)
@Override
public MutableSet<Pair<T, Integer>> zipWithIndex()
{
return Iterate.zipWithIndex(this, UnifiedSet.newSet(this.size()));
return Iterate.zipWithIndex(this, Sets.mutable.withInitialCapacity(this.size()));
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Goldman Sachs and others.
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.eclipse.collections.api.block.predicate.primitive.BytePredicate;
import org.eclipse.collections.api.block.procedure.primitive.ByteProcedure;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.primitive.ByteBags;
import org.eclipse.collections.api.factory.primitive.ByteLists;
import org.eclipse.collections.api.iterator.ByteIterator;
Expand All @@ -44,7 +45,6 @@
import org.eclipse.collections.impl.factory.primitive.ByteSets;
import org.eclipse.collections.impl.lazy.primitive.LazyByteIterableAdapter;
import org.eclipse.collections.impl.set.immutable.primitive.ImmutableByteSetSerializationProxy;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;

public final class ByteHashSet implements MutableByteSet, Externalizable
{
Expand Down Expand Up @@ -692,7 +692,7 @@ public MutableByteSet reject(BytePredicate predicate)
@Override
public <V> MutableSet<V> collect(ByteToObjectFunction<? extends V> function)
{
MutableSet<V> target = UnifiedSet.newSet(this.size());
MutableSet<V> target = Sets.mutable.withInitialCapacity(this.size());

this.forEach(each -> target.add(function.valueOf(each)));

Expand Down Expand Up @@ -1359,7 +1359,7 @@ public ImmutableByteSet reject(BytePredicate predicate)
@Override
public <V> ImmutableSet<V> collect(ByteToObjectFunction<? extends V> function)
{
MutableSet<V> target = UnifiedSet.newSet(this.size());
MutableSet<V> target = Sets.mutable.withInitialCapacity(this.size());

this.forEach(each -> target.add(function.valueOf(each)));

Expand Down

0 comments on commit 6999ba9

Please sign in to comment.