Top Methods
org.eclipse.collections.api.bag

public Interface MutableBagIterable<T>

extends Bag<T>, MutableCollection<T>
Known Direct Subinterfaces
org.eclipse.collections.api.bag.sorted.MutableSortedBag, org.eclipse.collections.api.bag.MutableBag
Imports
org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.block.function.Function, org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction, 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.collection.MutableCollection, org.eclipse.collections.api.list.MutableList, org.eclipse.collections.api.map.MutableMapIterable, org.eclipse.collections.api.multimap.bag.MutableBagIterableMultimap, org.eclipse.collections.api.partition.bag.PartitionMutableBagIterable, org.eclipse.collections.api.set.MutableSetIterable, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.api.tuple.primitive.ObjectIntPair

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

updated number of occurrences.
addOccurrences
(T item, int occurrences)

Add number of occurrences for an item.

public MutableList<ObjectIntPair<T>>
bottomOccurrences(int count)

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

Returns the count least frequently occurring items.

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

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

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

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

Redeclares org.eclipse.collections.api.bag.Bag.groupBy, org.eclipse.collections.api.collection.MutableCollection.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> MutableBagIterableMultimap<V, T>
groupByEach(Function<? super T, ? extends Iterable<V>> function)

Redeclares org.eclipse.collections.api.bag.Bag.groupByEach, org.eclipse.collections.api.collection.MutableCollection.groupByEach.

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

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

Redeclares org.eclipse.collections.api.bag.Bag.partition, org.eclipse.collections.api.collection.MutableCollection.partition.

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

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

Redeclares org.eclipse.collections.api.bag.Bag.partitionWith, org.eclipse.collections.api.collection.MutableCollection.partitionWith.

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

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

Redeclares org.eclipse.collections.api.bag.Bag.reject, org.eclipse.collections.api.collection.MutableCollection.reject.

Returns a MutableCollection with all elements that evaluate to false for the specified predicate.

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

Redeclares org.eclipse.collections.api.bag.Bag.rejectWith, org.eclipse.collections.api.collection.MutableCollection.rejectWith.

Returns a MutableCollection with all elements that evaluate to false for the specified predicate2 and parameter.

public boolean
removeOccurrences(Object item, int occurrences)

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

Redeclares org.eclipse.collections.api.bag.Bag.select, org.eclipse.collections.api.collection.MutableCollection.select.

Returns a MutableCollection with all elements that evaluate to true for the specified predicate.

public MutableBagIterable<T>
selectByOccurrences(IntPredicate predicate)

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

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

public default MutableBagIterable<T>
selectDuplicates()

Overrides default org.eclipse.collections.api.bag.Bag.selectDuplicates.

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

public <S> MutableBagIterable<S>
selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.bag.Bag.selectInstancesOf, org.eclipse.collections.api.collection.MutableCollection.selectInstancesOf.

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

public MutableSetIterable<T>
selectUnique()

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

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

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

Redeclares org.eclipse.collections.api.bag.Bag.selectWith, org.eclipse.collections.api.collection.MutableCollection.selectWith.

Returns a MutableCollection with all elements that evaluate to true for the specified predicate2 and parameter.

public boolean
setOccurrences(T item, int occurrences)

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

Redeclares org.eclipse.collections.api.bag.Bag.tap, org.eclipse.collections.api.collection.MutableCollection.tap.

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

public MutableMapIterable<T, Integer>
toMapOfItemToCount()

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

Converts the Bag to a Map of the Item type to its count as an Integer.

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

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

Returns the count most frequently occurring items.

public default MutableBagIterable<T>
with(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements.

public default MutableBagIterable<T>
withAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements.

public default MutableBagIterable<T>
withOccurrences(T element, int occurrences)

public default MutableBagIterable<T>
without(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements.

public default MutableBagIterable<T>
withoutAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements.

public default MutableBagIterable<T>
withoutOccurrences(T element, int occurrences)

public MutableSetIterable<Pair<T, Integer>>
Inherited from org.eclipse.collections.api.bag.Bag:
aggregateByallSatisfyWithOccurrencesanySatisfyWithOccurrencescollectWithOccurrencesdetectWithOccurrencesdistinctViewequalsforEachWithOccurrenceshashCodenoneSatisfyWithOccurrencesoccurrencesOfreduceByreduceInPlacereduceInPlacesizeDistinctsummarizeDoublesummarizeFloatsummarizeIntsummarizeLongtoImmutabletoStringOfItemToCount
Inherited from org.eclipse.collections.api.collection.MutableCollection:
addAllIterableaggregateByaggregateInPlaceByasSynchronizedasUnmodifiablecollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectLongcollectShortcollectWithcountBycountByEachcountByWithflatCollectflatCollectWithgroupByUniqueKeyinjectIntoWithnewEmptyremoveAllIterableremoveIfremoveIfWithretainAllIterableselectAndRejectWithsumByDoublesumByFloatsumByIntsumByLongtoArraytoArraytoImmutablezip

Method Detail

addOccurrencesback to summary
public int addOccurrences(T item, int occurrences)

Add number of occurrences for an item. If the item does not exist, then the item is added to the bag.

For Example:

MutableBagIterable<String> names = Bags.mutable.of("A", "B", "B");
Assert.assertEquals(4, names.addOccurrences("A", 3));
Returns:int

updated number of occurrences.

Exceptions
IllegalArgumentException:
if occurrences are less than 0.
bottomOccurrencesback to summary
public MutableList<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
collectWithOccurrencesback to summary
public <V> RichIterable<V> collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.Bag.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
groupByback to summary
public <V> MutableBagIterableMultimap<V, T> groupBy(Function<? super T, ? extends V> function)

Redeclares org.eclipse.collections.api.bag.Bag.groupBy, org.eclipse.collections.api.collection.MutableCollection.groupBy.

Doc from org.eclipse.collections.api.collection.MutableCollection.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);
Co-variant example for MutableCollection:
MutableMultimap<String, Person> peopleByLastName =
    people.groupBy(Person::getLastName);
Annotations
@Override
groupByEachback to summary
public <V> MutableBagIterableMultimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function)

Redeclares org.eclipse.collections.api.bag.Bag.groupByEach, org.eclipse.collections.api.collection.MutableCollection.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
partitionback to summary
public PartitionMutableBagIterable<T> partition(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.Bag.partition, org.eclipse.collections.api.collection.MutableCollection.partition.

Doc from org.eclipse.collections.api.collection.MutableCollection.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"));
Co-variant example for MutableCollection:
PartitionMutableCollection<Person> newYorkersAndNonNewYorkers =
    people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Annotations
@Override
partitionWithback to summary
public <P> PartitionMutableBagIterable<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.Bag.partitionWith, org.eclipse.collections.api.collection.MutableCollection.partitionWith.

Doc from org.eclipse.collections.api.collection.MutableCollection.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");
Co-variant example for MutableCollection:
PartitionMutableCollection<Person> newYorkersAndNonNewYorkers =
    people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");
Annotations
@Override
rejectback to summary
public MutableBagIterable<T> reject(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.Bag.reject, org.eclipse.collections.api.collection.MutableCollection.reject.

Doc from org.eclipse.collections.api.collection.MutableCollection.reject.

Returns a MutableCollection with all elements that evaluate to false for the specified predicate.

MutableCollection<Person> notSmiths =
    people.reject(person -> person.person.getLastName().equals("Smith"));
Using the Predicates factory:
MutableCollection<Person> notSmiths = people.reject(Predicates.attributeEqual("lastName", "Smith"));
Annotations
@Override
rejectWithback to summary
public <P> MutableBagIterable<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.Bag.rejectWith, org.eclipse.collections.api.collection.MutableCollection.rejectWith.

Doc from org.eclipse.collections.api.collection.MutableCollection.rejectWith.

Returns a MutableCollection with all elements that evaluate to false for the specified predicate2 and parameter.

e.g.
MutableCollection<Integer> selected =
    integers.rejectWith(Predicates2.equal(), Integer.valueOf(5));
Annotations
@Override
removeOccurrencesback to summary
public boolean removeOccurrences(Object item, int occurrences)
selectback to summary
public MutableBagIterable<T> select(Predicate<? super T> predicate)

Redeclares org.eclipse.collections.api.bag.Bag.select, org.eclipse.collections.api.collection.MutableCollection.select.

Doc from org.eclipse.collections.api.collection.MutableCollection.select.

Returns a MutableCollection with all elements that evaluate to true for the specified predicate.

MutableCollection<Integer> livesInLondon =
    people.select(person -> person.getAddress().getCity().equals("London"));
Annotations
@Override
selectByOccurrencesback to summary
public MutableBagIterable<T> selectByOccurrences(IntPredicate predicate)

Redeclares org.eclipse.collections.api.bag.Bag.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 MutableBagIterable<T> selectDuplicates()

Overrides default org.eclipse.collections.api.bag.Bag.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> MutableBagIterable<S> selectInstancesOf(Class<S> clazz)

Redeclares org.eclipse.collections.api.bag.Bag.selectInstancesOf, org.eclipse.collections.api.collection.MutableCollection.selectInstancesOf.

Doc from org.eclipse.collections.api.collection.MutableCollection.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);
Co-variant example for MutableCollection:
MutableCollection<Integer> integers =
    List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
Annotations
@Override
selectUniqueback to summary
public MutableSetIterable<T> selectUnique()

Redeclares org.eclipse.collections.api.bag.Bag.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> MutableBagIterable<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Redeclares org.eclipse.collections.api.bag.Bag.selectWith, org.eclipse.collections.api.collection.MutableCollection.selectWith.

Doc from org.eclipse.collections.api.collection.MutableCollection.selectWith.

Returns a MutableCollection with all elements that evaluate to true for the specified predicate2 and parameter.

MutableCollection<Integer> fives =
    integers.selectWith(Predicates2.equal(), Integer.valueOf(5));
Annotations
@Override
setOccurrencesback to summary
public boolean setOccurrences(T item, int occurrences)
tapback to summary
public MutableBagIterable<T> tap(Procedure<? super T> procedure)

Redeclares org.eclipse.collections.api.bag.Bag.tap, org.eclipse.collections.api.collection.MutableCollection.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
toMapOfItemToCountback to summary
public MutableMapIterable<T, Integer> toMapOfItemToCount()

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

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

Converts the Bag to a Map of the Item type to its count as an Integer.

Annotations
@Override
topOccurrencesback to summary
public MutableList<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
withback to summary
public default MutableBagIterable<T> with(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.with.

Doc from org.eclipse.collections.api.collection.MutableCollection.with.

This method allows mutable and fixed size collections the ability to add elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new element to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.with("1");
list = list.with("2");
return list;
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by with, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling add on itself.
Annotations
@Override
withAllback to summary
public default MutableBagIterable<T> withAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withAll.

This method allows mutable and fixed size collections the ability to add multiple elements to their existing elements. In order to support fixed size a new instance of a collection would have to be returned taking the elements of the original collection and appending the new elements to form the new collection. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.withAll(FastList.newListWith("1", "2"));
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling addAll on itself.
Annotations
@Override
withOccurrencesback to summary
public default MutableBagIterable<T> withOccurrences(T element, int occurrences)
withoutback to summary
public default MutableBagIterable<T> without(T element)

Implements org.eclipse.collections.api.collection.MutableCollection.without.

Doc from org.eclipse.collections.api.collection.MutableCollection.without.

This method allows mutable and fixed size collections the ability to remove elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling remove. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.without("1");
list = list.without("2");
return list;
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by without, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling remove on itself.
Annotations
@Override
withoutAllback to summary
public default MutableBagIterable<T> withoutAll(Iterable<? extends T> elements)

Implements org.eclipse.collections.api.collection.MutableCollection.withoutAll.

Doc from org.eclipse.collections.api.collection.MutableCollection.withoutAll.

This method allows mutable and fixed size collections the ability to remove multiple elements from their existing elements. In order to support fixed size a new instance of a collection would have to be returned containing the elements that would be left from the original collection after calling removeAll. In the case of mutable collections, the original collection is modified, and is returned. In order to use this method properly with mutable and fixed size collections the following approach must be taken:

MutableCollection<String> list = list.withoutAll(FastList.newListWith("1", "2"));
In the case of FixedSizeCollection a new instance of MutableCollection will be returned by withoutAll, and any variables that previously referenced the original collection will need to be redirected to reference the new instance. For other MutableCollection types you will replace the reference to collection with the same collection, since the instance will return "this" after calling removeAll on itself.
Annotations
@Override
withoutOccurrencesback to summary
public default MutableBagIterable<T> withoutOccurrences(T element, int occurrences)
zipWithIndexback to summary
public MutableSetIterable<Pair<T, Integer>> zipWithIndex()

Redeclares org.eclipse.collections.api.bag.Bag.zipWithIndex, org.eclipse.collections.api.collection.MutableCollection.zipWithIndex.

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

Zips this RichIterable with its indices.

Annotations
@Override