Top Methods
org.eclipse.collections.api.bag

public Interface ImmutableBag<T>

extends UnsortedBag<T>, ImmutableBagIterable<T>
Imports
org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag, .ImmutableByteBag, .ImmutableCharBag, .ImmutableDoubleBag, .ImmutableFloatBag, .ImmutableIntBag, .ImmutableLongBag, .ImmutableShortBag, org.eclipse.collections.api.block.function.Function, .Function2, org.eclipse.collections.api.block.function.primitive.BooleanFunction, .ByteFunction, .CharFunction, .DoubleFunction, .FloatFunction, .IntFunction, .LongFunction, .ObjectIntToObjectFunction, .ShortFunction, org.eclipse.collections.api.block.predicate.Predicate, .Predicate2, org.eclipse.collections.api.block.predicate.primitive.IntPredicate, org.eclipse.collections.api.block.procedure.Procedure, org.eclipse.collections.api.factory.Sets, org.eclipse.collections.api.list.ImmutableList, org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap, org.eclipse.collections.api.ordered.OrderedIterable, org.eclipse.collections.api.partition.bag.PartitionImmutableBag, org.eclipse.collections.api.set.ImmutableSet, .MutableSet, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.api.tuple.primitive.ObjectIntPair

Since
1.0

Method Summary

Modifier and TypeMethod and Description
public ImmutableList<ObjectIntPair<T>>
bottomOccurrences(int count)

Redeclares org.eclipse.collections.api.bag.Bag.bottomOccurrences.

Returns the count least frequently occurring items.

public <V> ImmutableBag<V>
collect(Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collect, org.eclipse.collections.api.RichIterable.collect, org.eclipse.collections.api.collection.ImmutableCollection.collect.

Returns a new collection with the results of applying the specified function on each element of the source collection.

public ImmutableBooleanBag
collectBoolean(BooleanFunction<? super T> booleanFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectBoolean, org.eclipse.collections.api.RichIterable.collectBoolean, org.eclipse.collections.api.collection.ImmutableCollection.collectBoolean.

Returns a new primitive boolean iterable with the results of applying the specified function on each element of the source collection.

public ImmutableByteBag
collectByte(ByteFunction<? super T> byteFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectByte, org.eclipse.collections.api.RichIterable.collectByte, org.eclipse.collections.api.collection.ImmutableCollection.collectByte.

Returns a new primitive byte iterable with the results of applying the specified function on each element of the source collection.

public ImmutableCharBag
collectChar(CharFunction<? super T> charFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectChar, org.eclipse.collections.api.RichIterable.collectChar, org.eclipse.collections.api.collection.ImmutableCollection.collectChar.

Returns a new primitive char iterable with the results of applying the specified function on each element of the source collection.

public ImmutableDoubleBag
collectDouble(DoubleFunction<? super T> doubleFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectDouble, org.eclipse.collections.api.RichIterable.collectDouble, org.eclipse.collections.api.collection.ImmutableCollection.collectDouble.

Returns a new primitive double iterable with the results of applying the specified function on each element of the source collection.

public ImmutableFloatBag
collectFloat(FloatFunction<? super T> floatFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectFloat, org.eclipse.collections.api.RichIterable.collectFloat, org.eclipse.collections.api.collection.ImmutableCollection.collectFloat.

Returns a new primitive float iterable with the results of applying the specified function on each element of the source collection.

public <V> ImmutableBag<V>
collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectIf, org.eclipse.collections.api.RichIterable.collectIf, org.eclipse.collections.api.collection.ImmutableCollection.collectIf.

Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate.

public ImmutableIntBag
collectInt(IntFunction<? super T> intFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectInt, org.eclipse.collections.api.RichIterable.collectInt, org.eclipse.collections.api.collection.ImmutableCollection.collectInt.

Returns a new primitive int iterable with the results of applying the specified function on each element of the source collection.

public ImmutableLongBag
collectLong(LongFunction<? super T> longFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectLong, org.eclipse.collections.api.RichIterable.collectLong, org.eclipse.collections.api.collection.ImmutableCollection.collectLong.

Returns a new primitive long iterable with the results of applying the specified function on each element of the source collection.

public ImmutableShortBag
collectShort(ShortFunction<? super T> shortFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectShort, org.eclipse.collections.api.RichIterable.collectShort, org.eclipse.collections.api.collection.ImmutableCollection.collectShort.

Returns a new primitive short iterable with the results of applying the specified function on each element of the source collection.

public <P, V> ImmutableBag<V>
collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectWith, org.eclipse.collections.api.RichIterable.collectWith, org.eclipse.collections.api.collection.ImmutableCollection.collectWith.

Same as collect(Function) with a Function2 and specified parameter which is passed to the block.

public <V> ImmutableBag<V>
collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectWithOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.collectWithOccurrences.

Iterates over the unique elements and their occurrences and collects the results of applying the specified function.

public default <V> ImmutableBag<V>
countBy(Function<? super T, ? extends V> function)

Overrides default org.eclipse.collections.api.RichIterable.countBy, org.eclipse.collections.api.collection.ImmutableCollection.countBy.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.

public default <V> ImmutableBag<V>
countByEach(Function<? super T, ? extends Iterable<V>> function)

Overrides default org.eclipse.collections.api.RichIterable.countByEach, org.eclipse.collections.api.collection.ImmutableCollection.countByEach.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.

public default <V, P> ImmutableBag<V>
countByWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Overrides default org.eclipse.collections.api.RichIterable.countByWith, org.eclipse.collections.api.collection.ImmutableCollection.countByWith.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.

public <V> ImmutableBag<V>
public default <P, V> ImmutableBag<V>
flatCollectWith(Function2<? super T, ? super P, ? extends Iterable<V>> function, P parameter)

Overrides default org.eclipse.collections.api.bag.UnsortedBag.flatCollectWith, org.eclipse.collections.api.RichIterable.flatCollectWith, org.eclipse.collections.api.collection.ImmutableCollection.flatCollectWith.

Same as flatCollect, only with a Function2 that is passed an extra parameter.

public <V> ImmutableBagMultimap<V, T>
groupBy(Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.groupBy, org.eclipse.collections.api.bag.ImmutableBagIterable.groupBy.

For each element of the iterable, the function is evaluated and the results of these evaluations are collected into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) species of collection as the source iterable.

public <V> ImmutableBagMultimap<V, T>
groupByEach(Function<? super T, ? extends Iterable<V>> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.groupByEach, org.eclipse.collections.api.bag.ImmutableBagIterable.groupByEach.

Similar to groupBy(Function), except the result of evaluating function will return a collection of keys for each value.

public ImmutableBag<T>
newWith(T element)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWith.

This method is similar to the with method in MutableCollection with the difference that a new copy of this collection with the element appended will be returned.

public ImmutableBag<T>
newWithAll(Iterable<? extends T> elements)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithAll.

This method is similar to the withAll method in MutableCollection with the difference that a new copy of this collection with the elements appended will be returned.

public ImmutableBag<T>
newWithout(T element)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithout.

This method is similar to the without method in MutableCollection with the difference that a new copy of this collection with the element removed will be returned.

public ImmutableBag<T>
newWithoutAll(Iterable<? extends T> elements)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithoutAll.

This method is similar to the withoutAll method in MutableCollection with the difference that a new copy of this collection with the elements removed will be returned.

public PartitionImmutableBag<T>
partition(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.partition, org.eclipse.collections.api.bag.ImmutableBagIterable.partition.

Filters a collection into a PartitionedIterable based on the evaluation of the predicate.

public <P> PartitionImmutableBag<T>
partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.Bag.partitionWith, org.eclipse.collections.api.bag.ImmutableBagIterable.partitionWith.

Filters a collection into a PartitionIterable based on the evaluation of the predicate.

public ImmutableBag<T>
reject(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.reject, org.eclipse.collections.api.bag.ImmutableBagIterable.reject.

Returns all elements of the source collection that return false when evaluating of the predicate.

public <P> ImmutableBag<T>
rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.rejectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.rejectWith.

Similar to reject(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

public ImmutableBag<T>
select(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.select, org.eclipse.collections.api.bag.ImmutableBagIterable.select.

Returns all elements of the source collection that return true when evaluating the predicate.

public ImmutableBag<T>
selectByOccurrences(IntPredicate predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectByOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.selectByOccurrences.

Returns all elements of the bag that have a number of occurrences that satisfy the predicate.

public default ImmutableBag<T>
public <S> ImmutableBag<S>
selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectInstancesOf, org.eclipse.collections.api.bag.ImmutableBagIterable.selectInstancesOf.

Returns all elements of the source collection that are instances of the Class clazz.

public default ImmutableSet<T>
selectUnique()

Implements org.eclipse.collections.api.bag.UnsortedBag.selectUnique, org.eclipse.collections.api.bag.ImmutableBagIterable.selectUnique.

Returns a set containing all elements of the bag that have exactly one occurrence.

public <P> ImmutableBag<T>
selectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.selectWith.

Similar to select(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

public ImmutableBag<T>
tap(Procedure<? super T> procedure)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.tap, org.eclipse.collections.api.bag.ImmutableBagIterable.tap.

Executes the Procedure for each element in the iterable and returns this.

public default ImmutableBag<T>
toImmutableBag()

Overrides default org.eclipse.collections.api.RichIterable.toImmutableBag.

Overrides toImmutableBag in RichIterable to return this.

public ImmutableList<ObjectIntPair<T>>
topOccurrences(int count)

Redeclares org.eclipse.collections.api.bag.Bag.topOccurrences.

Returns the count most frequently occurring items.

public <S> ImmutableBag<Pair<T, S>>
zip(Iterable<S> that)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.zip, org.eclipse.collections.api.RichIterable.zip, org.eclipse.collections.api.collection.ImmutableCollection.zip.

Deprecated in 6.0. Use OrderedIterable#zip(Iterable) instead.

Returns a RichIterable formed from this RichIterable and another RichIterable by combining corresponding elements in pairs.

public ImmutableSet<Pair<T, Integer>>
Inherited from org.eclipse.collections.api.bag.ImmutableBagIterable:
toMapOfItemToCount

Method Detail

bottomOccurrencesback to summary
public ImmutableList<ObjectIntPair<T>> bottomOccurrences(int count)

Redeclares org.eclipse.collections.api.bag.Bag.bottomOccurrences.

Doc from org.eclipse.collections.api.bag.Bag.bottomOccurrences.

Returns the count least frequently occurring items. In the event of a tie, all of the items with the number of occurrences that match the occurrences of the last item will be returned.

Annotations
@Override
Since
6.0
collectback to summary
public <V> ImmutableBag<V> collect(Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collect, org.eclipse.collections.api.RichIterable.collect, org.eclipse.collections.api.collection.ImmutableCollection.collect.

Doc from org.eclipse.collections.api.RichIterable.collect.

Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

RichIterable<String> names =
    people.collect(person -> person.getFirstName() + " " + person.getLastName());
Annotations
@Override
collectBooleanback to summary
public ImmutableBooleanBag collectBoolean(BooleanFunction<? super T> booleanFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectBoolean, org.eclipse.collections.api.RichIterable.collectBoolean, org.eclipse.collections.api.collection.ImmutableCollection.collectBoolean.

Doc from org.eclipse.collections.api.RichIterable.collectBoolean.

Returns a new primitive boolean iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

BooleanIterable licenses =
    people.collectBoolean(person -> person.hasDrivingLicense());
Annotations
@Override
collectByteback to summary
public ImmutableByteBag collectByte(ByteFunction<? super T> byteFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectByte, org.eclipse.collections.api.RichIterable.collectByte, org.eclipse.collections.api.collection.ImmutableCollection.collectByte.

Doc from org.eclipse.collections.api.RichIterable.collectByte.

Returns a new primitive byte iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

ByteIterable bytes =
    people.collectByte(person -> person.getCode());
Annotations
@Override
collectCharback to summary
public ImmutableCharBag collectChar(CharFunction<? super T> charFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectChar, org.eclipse.collections.api.RichIterable.collectChar, org.eclipse.collections.api.collection.ImmutableCollection.collectChar.

Doc from org.eclipse.collections.api.RichIterable.collectChar.

Returns a new primitive char iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

CharIterable chars =
    people.collectChar(person -> person.getMiddleInitial());
Annotations
@Override
collectDoubleback to summary
public ImmutableDoubleBag collectDouble(DoubleFunction<? super T> doubleFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectDouble, org.eclipse.collections.api.RichIterable.collectDouble, org.eclipse.collections.api.collection.ImmutableCollection.collectDouble.

Doc from org.eclipse.collections.api.RichIterable.collectDouble.

Returns a new primitive double iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

DoubleIterable doubles =
    people.collectDouble(person -> person.getMilesFromNorthPole());
Annotations
@Override
collectFloatback to summary
public ImmutableFloatBag collectFloat(FloatFunction<? super T> floatFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectFloat, org.eclipse.collections.api.RichIterable.collectFloat, org.eclipse.collections.api.collection.ImmutableCollection.collectFloat.

Doc from org.eclipse.collections.api.RichIterable.collectFloat.

Returns a new primitive float iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

FloatIterable floats =
    people.collectFloat(person -> person.getHeightInInches());
Annotations
@Override
collectIfback to summary
public <V> ImmutableBag<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectIf, org.eclipse.collections.api.RichIterable.collectIf, org.eclipse.collections.api.collection.ImmutableCollection.collectIf.

Doc from org.eclipse.collections.api.RichIterable.collectIf.

Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate. This is the optimized equivalent of calling iterable.select(predicate).collect(function).

Example using a Java 8 lambda and method reference:

RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);

Example using Predicates factory:

RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
Annotations
@Override
collectIntback to summary
public ImmutableIntBag collectInt(IntFunction<? super T> intFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectInt, org.eclipse.collections.api.RichIterable.collectInt, org.eclipse.collections.api.collection.ImmutableCollection.collectInt.

Doc from org.eclipse.collections.api.RichIterable.collectInt.

Returns a new primitive int iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

IntIterable ints =
    people.collectInt(person -> person.getAge());
Annotations
@Override
collectLongback to summary
public ImmutableLongBag collectLong(LongFunction<? super T> longFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectLong, org.eclipse.collections.api.RichIterable.collectLong, org.eclipse.collections.api.collection.ImmutableCollection.collectLong.

Doc from org.eclipse.collections.api.RichIterable.collectLong.

Returns a new primitive long iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

LongIterable longs =
    people.collectLong(person -> person.getGuid());
Annotations
@Override
collectShortback to summary
public ImmutableShortBag collectShort(ShortFunction<? super T> shortFunction)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectShort, org.eclipse.collections.api.RichIterable.collectShort, org.eclipse.collections.api.collection.ImmutableCollection.collectShort.

Doc from org.eclipse.collections.api.RichIterable.collectShort.

Returns a new primitive short iterable with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.

Example using a Java 8 lambda expression:

ShortIterable shorts =
    people.collectShort(person -> person.getNumberOfJunkMailItemsReceivedPerMonth());
Annotations
@Override
collectWithback to summary
public <P, V> ImmutableBag<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectWith, org.eclipse.collections.api.RichIterable.collectWith, org.eclipse.collections.api.collection.ImmutableCollection.collectWith.

Doc from org.eclipse.collections.api.RichIterable.collectWith.

Same as collect(Function) with a Function2 and specified parameter which is passed to the block.

Example using a Java 8 lambda expression:

RichIterable<Integer> integers =
    Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
Annotations
@Override
collectWithOccurrencesback to summary
public <V> ImmutableBag<V> collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.collectWithOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.collectWithOccurrences.

Doc from org.eclipse.collections.api.bag.Bag.collectWithOccurrences.

Iterates over the unique elements and their occurrences and collects the results of applying the specified function.

Annotations
@Override
countByback to summary
public default <V> ImmutableBag<V> countBy(Function<? super T, ? extends V> function)

Overrides default org.eclipse.collections.api.RichIterable.countBy, org.eclipse.collections.api.collection.ImmutableCollection.countBy.

Doc from org.eclipse.collections.api.RichIterable.countBy.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.

Annotations
@Override
Since
9.0
countByEachback to summary
public default <V> ImmutableBag<V> countByEach(Function<? super T, ? extends Iterable<V>> function)

Overrides default org.eclipse.collections.api.RichIterable.countByEach, org.eclipse.collections.api.collection.ImmutableCollection.countByEach.

Doc from org.eclipse.collections.api.RichIterable.countByEach.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.

Annotations
@Override
Since
10.0.0
countByWithback to summary
public default <V, P> ImmutableBag<V> countByWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Overrides default org.eclipse.collections.api.RichIterable.countByWith, org.eclipse.collections.api.collection.ImmutableCollection.countByWith.

Doc from org.eclipse.collections.api.RichIterable.countByWith.

This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.

Annotations
@Override
Since
9.0
flatCollectback to summary
public <V> ImmutableBag<V> flatCollect(Function<? super T, ? extends Iterable<V>> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.flatCollect, org.eclipse.collections.api.RichIterable.flatCollect, org.eclipse.collections.api.collection.ImmutableCollection.flatCollect.

Doc from org.eclipse.collections.api.RichIterable.flatCollect.

flatCollect is a special case of collect(Function). With collect, when the Function returns a collection, the result is a collection of collections. flatCollect outputs a single "flattened" collection instead. This method is commonly called flatMap.

Consider the following example where we have a Person class, and each Person has a list of Address objects. Take the following Function:

Function<Person, List<Address>> addressFunction = Person::getAddresses;
RichIterable<Person> people = ...;
Using collect returns a collection of collections of addresses.
RichIterable<List<Address>> addresses = people.collect(addressFunction);
Using flatCollect returns a single flattened list of addresses.
RichIterable<Address> addresses = people.flatCollect(addressFunction);
Annotations
@Override
flatCollectWithback to summary
public default <P, V> ImmutableBag<V> flatCollectWith(Function2<? super T, ? super P, ? extends Iterable<V>> function, P parameter)

Overrides default org.eclipse.collections.api.bag.UnsortedBag.flatCollectWith, org.eclipse.collections.api.RichIterable.flatCollectWith, org.eclipse.collections.api.collection.ImmutableCollection.flatCollectWith.

Doc from org.eclipse.collections.api.RichIterable.flatCollectWith.

Same as flatCollect, only with a Function2 that is passed an extra parameter.

Annotations
@Override
Since
9.2
groupByback to summary
public <V> ImmutableBagMultimap<V, T> groupBy(Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.groupBy, org.eclipse.collections.api.bag.ImmutableBagIterable.groupBy.

Doc from org.eclipse.collections.api.RichIterable.groupBy.

For each element of the iterable, the function is evaluated and the results of these evaluations are collected into a new multimap, where the transformed value is the key and the original values are added to the same (or similar) species of collection as the source iterable.

Example using a Java 8 method reference:

Multimap<String, Person> peopleByLastName =
    people.groupBy(Person::getLastName);
Annotations
@Override
groupByEachback to summary
public <V> ImmutableBagMultimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.groupByEach, org.eclipse.collections.api.bag.ImmutableBagIterable.groupByEach.

Doc from org.eclipse.collections.api.RichIterable.groupByEach.

Similar to groupBy(Function), except the result of evaluating function will return a collection of keys for each value.

Annotations
@Override
newWithback to summary
public ImmutableBag<T> newWith(T element)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWith.

Doc from org.eclipse.collections.api.collection.ImmutableCollection.newWith.

This method is similar to the with method in MutableCollection with the difference that a new copy of this collection with the element appended will be returned.

Annotations
@Override
newWithAllback to summary
public ImmutableBag<T> newWithAll(Iterable<? extends T> elements)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithAll.

Doc from org.eclipse.collections.api.collection.ImmutableCollection.newWithAll.

This method is similar to the withAll method in MutableCollection with the difference that a new copy of this collection with the elements appended will be returned.

Annotations
@Override
newWithoutback to summary
public ImmutableBag<T> newWithout(T element)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithout.

Doc from org.eclipse.collections.api.collection.ImmutableCollection.newWithout.

This method is similar to the without method in MutableCollection with the difference that a new copy of this collection with the element removed will be returned.

Annotations
@Override
newWithoutAllback to summary
public ImmutableBag<T> newWithoutAll(Iterable<? extends T> elements)

Redeclares org.eclipse.collections.api.collection.ImmutableCollection.newWithoutAll.

Doc from org.eclipse.collections.api.collection.ImmutableCollection.newWithoutAll.

This method is similar to the withoutAll method in MutableCollection with the difference that a new copy of this collection with the elements removed will be returned.

Annotations
@Override
partitionback to summary
public PartitionImmutableBag<T> partition(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.partition, org.eclipse.collections.api.bag.ImmutableBagIterable.partition.

Doc from org.eclipse.collections.api.RichIterable.partition.

Filters a collection into a PartitionedIterable based on the evaluation of the predicate.

Example using a Java 8 lambda expression:

PartitionIterable<Person> newYorkersAndNonNewYorkers =
    people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Annotations
@Override
partitionWithback to summary
public <P> PartitionImmutableBag<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.Bag.partitionWith, org.eclipse.collections.api.bag.ImmutableBagIterable.partitionWith.

Doc from org.eclipse.collections.api.RichIterable.partitionWith.

Filters a collection into a PartitionIterable based on the evaluation of the predicate.

Example using a Java 8 lambda expression:

PartitionIterable<Person> newYorkersAndNonNewYorkers =
    people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Annotations
@Override
rejectback to summary
public ImmutableBag<T> reject(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.reject, org.eclipse.collections.api.bag.ImmutableBagIterable.reject.

Doc from org.eclipse.collections.api.RichIterable.reject.

Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).

Example using a Java 8 lambda expression:

RichIterable<Person> rejected =
    people.reject(person -> person.person.getLastName().equals("Smith"));
Annotations
@Override
rejectWithback to summary
public <P> ImmutableBag<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.rejectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.rejectWith.

Doc from org.eclipse.collections.api.RichIterable.rejectWith.

Similar to reject(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

Example using a Java 8 lambda expression:

RichIterable<Person> rejected =
    people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
Annotations
@Override
selectback to summary
public ImmutableBag<T> select(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.select, org.eclipse.collections.api.bag.ImmutableBagIterable.select.

Doc from org.eclipse.collections.api.RichIterable.select.

Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.

Example using a Java 8 lambda expression:

RichIterable<Person> selected =
    people.select(person -> person.getAddress().getCity().equals("London"));
Annotations
@Override
selectByOccurrencesback to summary
public ImmutableBag<T> selectByOccurrences(IntPredicate predicate)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectByOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.selectByOccurrences.

Doc from org.eclipse.collections.api.bag.Bag.selectByOccurrences.

Returns all elements of the bag that have a number of occurrences that satisfy the predicate.

Annotations
@Override
selectDuplicatesback to summary
public default ImmutableBag<T> selectDuplicates()

Overrides default org.eclipse.collections.api.bag.UnsortedBag.selectDuplicates, org.eclipse.collections.api.bag.ImmutableBagIterable.selectDuplicates.

Doc from org.eclipse.collections.api.bag.Bag.selectDuplicates.

Returns all elements of the bag that have more than one occurrence.

Annotations
@Override
Since
9.2
selectInstancesOfback to summary
public <S> ImmutableBag<S> selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectInstancesOf, org.eclipse.collections.api.bag.ImmutableBagIterable.selectInstancesOf.

Doc from org.eclipse.collections.api.RichIterable.selectInstancesOf.

Returns all elements of the source collection that are instances of the Class clazz.

RichIterable<Integer> integers =
    List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
Annotations
@Override
selectUniqueback to summary
public default ImmutableSet<T> selectUnique()

Implements org.eclipse.collections.api.bag.UnsortedBag.selectUnique, org.eclipse.collections.api.bag.ImmutableBagIterable.selectUnique.

Doc from org.eclipse.collections.api.bag.Bag.selectUnique.

Returns a set containing all elements of the bag that have exactly one occurrence.

Annotations
@Override
Since
9.2
selectWithback to summary
public <P> ImmutableBag<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.selectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.selectWith.

Doc from org.eclipse.collections.api.RichIterable.selectWith.

Similar to select(Predicate), except with an evaluation parameter for the second generic argument in Predicate2.

E.g. return a Collection of Person elements where the person has an age greater than or equal to 18 years

Example using a Java 8 lambda expression:

RichIterable<Person> selected =
    people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
Annotations
@Override
tapback to summary
public ImmutableBag<T> tap(Procedure<? super T> procedure)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.tap, org.eclipse.collections.api.bag.ImmutableBagIterable.tap.

Doc from org.eclipse.collections.api.RichIterable.tap.

Executes the Procedure for each element in the iterable and returns this.

Example using a Java 8 lambda expression:

RichIterable<Person> tapped =
    people.tap(person -> LOGGER.info(person.getName()));
Annotations
@Override
toImmutableBagback to summary
public default ImmutableBag<T> toImmutableBag()

Overrides default org.eclipse.collections.api.RichIterable.toImmutableBag.

Overrides toImmutableBag in RichIterable to return this.

Annotations
@Override
Since
11.0
topOccurrencesback to summary
public ImmutableList<ObjectIntPair<T>> topOccurrences(int count)

Redeclares org.eclipse.collections.api.bag.Bag.topOccurrences.

Doc from org.eclipse.collections.api.bag.Bag.topOccurrences.

Returns the count most frequently occurring items. In the event of a tie, all the items with the number of occurrences that match the occurrences of the last item will be returned.

Annotations
@Override
Since
6.0
zipback to summary
public <S> ImmutableBag<Pair<T, S>> zip(Iterable<S> that)

Redeclares org.eclipse.collections.api.bag.UnsortedBag.zip, org.eclipse.collections.api.RichIterable.zip, org.eclipse.collections.api.collection.ImmutableCollection.zip.

Doc from org.eclipse.collections.api.RichIterable.zip.

Deprecated

in 6.0. Use OrderedIterable#zip(Iterable) instead.

Returns a RichIterable formed from this RichIterable and another RichIterable by combining corresponding elements in pairs. If one of the two RichIterables is longer than the other, its remaining elements are ignored.

Annotations
@Override
@Deprecated
zipWithIndexback to summary
public ImmutableSet<Pair<T, Integer>> zipWithIndex()

Redeclares org.eclipse.collections.api.bag.UnsortedBag.zipWithIndex, org.eclipse.collections.api.bag.ImmutableBagIterable.zipWithIndex.

Doc from org.eclipse.collections.api.RichIterable.zipWithIndex.

Deprecated

in 6.0. Use OrderedIterable#zipWithIndex() instead.

Zips this RichIterable with its indices.

Annotations
@Override
@Deprecated