Skip to content

Commit

Permalink
Merge pull request #1327 from motlin/impl-to-api
Browse files Browse the repository at this point in the history
  • Loading branch information
motlin committed Apr 19, 2022
2 parents c9048ec + 6250257 commit 36ab4c8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .idea/inspectionProfiles/IDE.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.SortedBags;
import org.eclipse.collections.api.factory.SortedMaps;
import org.eclipse.collections.api.factory.SortedSets;
import org.eclipse.collections.api.list.MutableList;
Expand Down Expand Up @@ -206,7 +207,7 @@ public MutableSortedBag<T> toSortedBag()
@Override
public MutableSortedBag<T> toSortedBag(Comparator<? super T> comparator)
{
MutableSortedBag<T> sortedBag = TreeBag.newBag(comparator);
MutableSortedBag<T> sortedBag = SortedBags.mutable.empty(comparator);
this.forEachWith(Procedures2.addToCollection(), sortedBag);
return sortedBag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.SortedBags;
import org.eclipse.collections.api.factory.SortedSets;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.multimap.MutableMultimap;
Expand Down Expand Up @@ -938,7 +939,7 @@ public MutableSortedBag<T> toSortedBag()
@Override
public MutableSortedBag<T> toSortedBag(Comparator<? super T> comparator)
{
MutableSortedBag<T> result = TreeBag.newBag(comparator);
MutableSortedBag<T> result = SortedBags.mutable.empty(comparator);
this.forEachWithOccurrences(result::addOccurrences);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.SortedBags;
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 @@ -605,7 +606,7 @@ public MutableSortedBag<T> toSortedBag()
@Override
public MutableSortedBag<T> toSortedBag(Comparator<? super T> comparator)
{
return TreeBag.newBag(comparator);
return SortedBags.mutable.empty(comparator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.collections.api.collection.MutableCollection;
import org.eclipse.collections.api.factory.Bags;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.SortedBags;
import org.eclipse.collections.api.factory.Stacks;
import org.eclipse.collections.api.factory.primitive.BooleanLists;
import org.eclipse.collections.api.factory.primitive.ByteLists;
Expand Down Expand Up @@ -66,7 +67,6 @@
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
import org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable;
import org.eclipse.collections.impl.bag.sorted.mutable.TreeBag;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.factory.Functions;
import org.eclipse.collections.impl.block.factory.Predicates;
Expand Down Expand Up @@ -157,25 +157,25 @@ public <V> ImmutableMap<V, T> groupByUniqueKey(Function<? super T, ? extends V>
@Override
public ImmutableSortedBag<T> select(Predicate<? super T> predicate)
{
return this.select(predicate, TreeBag.newBag(this.comparator())).toImmutable();
return this.select(predicate, SortedBags.mutable.empty(this.comparator())).toImmutable();
}

@Override
public <P> ImmutableSortedBag<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.selectWith(predicate, parameter, TreeBag.newBag(this.comparator())).toImmutable();
return this.selectWith(predicate, parameter, SortedBags.mutable.empty(this.comparator())).toImmutable();
}

@Override
public ImmutableSortedBag<T> reject(Predicate<? super T> predicate)
{
return this.reject(predicate, TreeBag.newBag(this.comparator())).toImmutable();
return this.reject(predicate, SortedBags.mutable.empty(this.comparator())).toImmutable();
}

@Override
public <P> ImmutableSortedBag<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.rejectWith(predicate, parameter, TreeBag.newBag(this.comparator())).toImmutable();
return this.rejectWith(predicate, parameter, SortedBags.mutable.empty(this.comparator())).toImmutable();
}

@Override
Expand Down Expand Up @@ -285,7 +285,7 @@ public <V> ImmutableList<V> flatCollect(Function<? super T, ? extends Iterable<V
@Override
public ImmutableSortedBag<T> selectByOccurrences(IntPredicate predicate)
{
MutableSortedBag<T> result = TreeBag.newBag(this.comparator());
MutableSortedBag<T> result = SortedBags.mutable.empty(this.comparator());
this.forEachWithOccurrences((each, occurrences) ->
{
if (predicate.accept(occurrences))
Expand All @@ -300,7 +300,7 @@ public ImmutableSortedBag<T> selectByOccurrences(IntPredicate predicate)
public <S> ImmutableSortedBag<S> selectInstancesOf(Class<S> clazz)
{
Comparator<? super S> comparator = (Comparator<? super S>) this.comparator();
MutableSortedBag<S> result = TreeBag.newBag(comparator);
MutableSortedBag<S> result = SortedBags.mutable.empty(comparator);
this.forEachWithOccurrences((each, occurrences) ->
{
if (clazz.isInstance(each))
Expand Down Expand Up @@ -434,7 +434,7 @@ public RichIterable<RichIterable<T>> chunk(int size)

MutableList<RichIterable<T>> result = Lists.mutable.empty();
T[] objects = (T[]) this.toArray();
MutableCollection<T> batch = TreeBag.newBag(this.comparator());
MutableCollection<T> batch = SortedBags.mutable.empty(this.comparator());
int j = 0;

while (j < objects.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.collections.api.set.sorted.ImmutableSortedSet;
import org.eclipse.collections.api.set.sorted.MutableSortedSet;
import org.eclipse.collections.impl.Counter;
import org.eclipse.collections.impl.bag.sorted.mutable.TreeBag;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.list.fixed.ArrayAdapter;
import org.eclipse.collections.impl.list.mutable.FastList;
Expand Down Expand Up @@ -219,7 +218,7 @@ public <V extends Comparable<? super V>> T maxBy(Function<? super T, ? extends V
@Override
public ImmutableSortedBag<T> takeWhile(Predicate<? super T> predicate)
{
MutableSortedBag<T> bag = TreeBag.newBag(this.comparator);
MutableSortedBag<T> bag = SortedBags.mutable.empty(this.comparator);
for (int i = 0; i < this.elements.length; i++)
{
if (predicate.accept(this.elements[i]))
Expand All @@ -237,7 +236,7 @@ public ImmutableSortedBag<T> takeWhile(Predicate<? super T> predicate)
@Override
public ImmutableSortedBag<T> dropWhile(Predicate<? super T> predicate)
{
MutableSortedBag<T> bag = TreeBag.newBag(this.comparator);
MutableSortedBag<T> bag = SortedBags.mutable.empty(this.comparator);
int startIndex = this.detectNotIndex(predicate);
for (int i = startIndex; i < this.elements.length; i++)
{
Expand Down Expand Up @@ -708,7 +707,7 @@ public ImmutableSortedBag<T> take(int count)
return this;
}

MutableSortedBag<T> output = TreeBag.newBag(this.comparator());
MutableSortedBag<T> output = SortedBags.mutable.empty(this.comparator());
int index = 0;
for (int i = 0; i < this.elements.length; i++)
{
Expand Down Expand Up @@ -742,7 +741,7 @@ public ImmutableSortedBag<T> drop(int count)
return SortedBags.immutable.empty(this.comparator());
}

MutableSortedBag<T> output = TreeBag.newBag(this.comparator());
MutableSortedBag<T> output = SortedBags.mutable.empty(this.comparator());
int index = 0;
for (int i = 0; i < this.elements.length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public MutableSortedMap<T, Integer> toMapOfItemToCount()
public <S> MutableSortedBag<S> selectInstancesOf(Class<S> clazz)
{
Comparator<? super S> comparator = (Comparator<? super S>) this.comparator();
MutableSortedBag<S> result = TreeBag.newBag(comparator);
MutableSortedBag<S> result = SortedBags.mutable.empty(comparator);
this.forEachWithOccurrences((each, occurrences) -> {
if (clazz.isInstance(each))
{
Expand All @@ -122,14 +122,14 @@ public <S> MutableSortedBag<S> selectInstancesOf(Class<S> clazz)
@Override
public MutableSortedBag<T> takeWhile(Predicate<? super T> predicate)
{
MutableSortedBag<T> result = TreeBag.newBag(this.comparator());
MutableSortedBag<T> result = SortedBags.mutable.empty(this.comparator());
return IterableIterate.takeWhile(this, predicate, result);
}

@Override
public MutableSortedBag<T> dropWhile(Predicate<? super T> predicate)
{
MutableSortedBag<T> result = TreeBag.newBag(this.comparator());
MutableSortedBag<T> result = SortedBags.mutable.empty(this.comparator());
return IterableIterate.dropWhile(this, predicate, result);
}

Expand Down Expand Up @@ -163,25 +163,25 @@ public <V> MutableBag<V> countByEach(Function<? super T, ? extends Iterable<V>>
@Override
public MutableSortedBag<T> select(Predicate<? super T> predicate)
{
return this.select(predicate, TreeBag.newBag(this.comparator()));
return this.select(predicate, SortedBags.mutable.empty(this.comparator()));
}

@Override
public <P> MutableSortedBag<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.selectWith(predicate, parameter, TreeBag.newBag(this.comparator()));
return this.selectWith(predicate, parameter, SortedBags.mutable.empty(this.comparator()));
}

@Override
public MutableSortedBag<T> reject(Predicate<? super T> predicate)
{
return this.reject(predicate, TreeBag.newBag(this.comparator()));
return this.reject(predicate, SortedBags.mutable.empty(this.comparator()));
}

@Override
public <P> MutableSortedBag<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)
{
return this.rejectWith(predicate, parameter, TreeBag.newBag(this.comparator()));
return this.rejectWith(predicate, parameter, SortedBags.mutable.empty(this.comparator()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public <T> MutableSortedBag<T> empty()
@Override
public <T> MutableSortedBag<T> empty(Comparator<? super T> comparator)
{
//noinspection SSBasedInspection
return TreeBag.newBag(comparator);
}

Expand All @@ -52,6 +53,7 @@ public <T> MutableSortedBag<T> of(Comparator<? super T> comparator)
@Override
public <T> MutableSortedBag<T> with(Comparator<? super T> comparator)
{
//noinspection SSBasedInspection
return TreeBag.newBag(comparator);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 Down Expand Up @@ -38,6 +38,7 @@
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.SortedBags;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
Expand Down Expand Up @@ -538,7 +539,7 @@ public MutableSortedBag<T> toSortedBag()
@Override
public MutableSortedBag<T> toSortedBag(Comparator<? super T> comparator)
{
MutableSortedBag<T> result = TreeBag.newBag(comparator);
MutableSortedBag<T> result = SortedBags.mutable.empty(comparator);
result = result.asSynchronized();
this.forEach(CollectionAddProcedure.on(result));
return result;
Expand Down

0 comments on commit 36ab4c8

Please sign in to comment.