Top Constructors Methods
org.eclipse.collections.impl.bag.immutable

public abstract Class AbstractImmutableBag<T>

extends AbstractImmutableBagIterable<T>
implements ImmutableBag<T>
Class Inheritance
All Implemented Interfaces
org.eclipse.collections.api.bag.ImmutableBag, org.eclipse.collections.api.bag.ImmutableBagIterable, org.eclipse.collections.api.collection.ImmutableCollection, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.InternalIterable, java.lang.Iterable, org.eclipse.collections.api.bag.Bag, org.eclipse.collections.api.bag.UnsortedBag
Known Direct Subclasses
org.eclipse.collections.impl.bag.immutable.ImmutableArrayBag, org.eclipse.collections.impl.bag.immutable.ImmutableEmptyBag, org.eclipse.collections.impl.bag.immutable.ImmutableHashBag, org.eclipse.collections.impl.bag.immutable.ImmutableSingletonBag
Imports
java.util.Iterator, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.bag.ImmutableBag, .MutableBag, 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.procedure.Procedure, org.eclipse.collections.api.collection.MutableCollection, org.eclipse.collections.api.factory.Bags, .Lists, org.eclipse.collections.api.factory.primitive.BooleanBags, .ByteBags, .CharBags, .DoubleBags, .FloatBags, .IntBags, .LongBags, .ShortBags, org.eclipse.collections.api.list.ImmutableList, .MutableList, org.eclipse.collections.api.map.ImmutableMap, org.eclipse.collections.api.partition.bag.PartitionImmutableBag, .PartitionMutableBag, org.eclipse.collections.api.tuple.primitive.ObjectIntPair, org.eclipse.collections.impl.block.factory.Functions, .Predicates, org.eclipse.collections.impl.map.mutable.UnifiedMap, org.eclipse.collections.impl.partition.bag.PartitionHashBag

Since
1.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ImmutableList<ObjectIntPair<T>>
public RichIterable<RichIterable<T>>
chunk(int size)

Implements org.eclipse.collections.api.RichIterable.chunk.

Partitions elements in fixed size chunks.

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

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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 ImmutableIntBag
collectInt(IntFunction<? super T> intFunction)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.collectWithOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.collectWithOccurrences, 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> ImmutableBag<V>
countBy(Function<? super T, ? extends V> function)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countBy.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countBy, 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 <V> ImmutableBag<V>
countByEach(Function<? super T, ? extends Iterable<V>> function)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countByEach.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countByEach, 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 <V, P> ImmutableBag<V>
countByWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countByWith.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countByWith, 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> ImmutableMap<V, T>
groupByUniqueKey(Function<? super T, ? extends V> function)

Overrides default org.eclipse.collections.api.collection.ImmutableCollection.groupByUniqueKey.

Implements org.eclipse.collections.api.RichIterable.groupByUniqueKey.

For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key.

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

Implements org.eclipse.collections.api.bag.ImmutableBag.newWithoutAll, 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>
public <P> PartitionImmutableBag<T>
public <P> ImmutableBag<T>
public <P> ImmutableBag<T>
public ImmutableBag<T>
public ImmutableBag<T>
public ImmutableList<ObjectIntPair<T>>
Inherited from org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable:
addaddAllcastToCollectionclearparallelStreamremoveremoveAllremoveAllFromretainAllshortCircuitspliteratorstreamsumByDoublesumByFloatsumByIntsumByLong

Constructor Detail

AbstractImmutableBagback to summary
public AbstractImmutableBag()

Method Detail

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

Implements org.eclipse.collections.api.bag.ImmutableBag.bottomOccurrences, 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
chunkback to summary
public RichIterable<RichIterable<T>> chunk(int size)

Implements org.eclipse.collections.api.RichIterable.chunk.

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

Partitions elements in fixed size chunks.

Annotations
@Override
collectBooleanback to summary
public ImmutableBooleanBag collectBoolean(BooleanFunction<? super T> booleanFunction)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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
collectIntback to summary
public ImmutableIntBag collectInt(IntFunction<? super T> intFunction)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.collectWithOccurrences, org.eclipse.collections.api.bag.ImmutableBagIterable.collectWithOccurrences, 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
countByback to summary
public <V> ImmutableBag<V> countBy(Function<? super T, ? extends V> function)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countBy.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countBy, 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 <V> ImmutableBag<V> countByEach(Function<? super T, ? extends Iterable<V>> function)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countByEach.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countByEach, 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 <V, P> ImmutableBag<V> countByWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Overrides org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable.countByWith.

Overrides default org.eclipse.collections.api.bag.ImmutableBag.countByWith, 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
groupByUniqueKeyback to summary
public <V> ImmutableMap<V, T> groupByUniqueKey(Function<? super T, ? extends V> function)

Overrides default org.eclipse.collections.api.collection.ImmutableCollection.groupByUniqueKey.

Implements org.eclipse.collections.api.RichIterable.groupByUniqueKey.

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

For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key. The generated keys must each be unique, or else an exception is thrown.

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

Implements org.eclipse.collections.api.bag.ImmutableBag.newWithoutAll, 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)

Implements org.eclipse.collections.api.bag.ImmutableBag.partition, org.eclipse.collections.api.bag.ImmutableBagIterable.partition, org.eclipse.collections.api.bag.Bag.partition, org.eclipse.collections.api.RichIterable.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.partitionWith, org.eclipse.collections.api.bag.ImmutableBagIterable.partitionWith, org.eclipse.collections.api.bag.Bag.partitionWith, org.eclipse.collections.api.RichIterable.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
rejectWithback to summary
public <P> ImmutableBag<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Implements org.eclipse.collections.api.bag.ImmutableBag.rejectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.rejectWith, org.eclipse.collections.api.bag.Bag.rejectWith, org.eclipse.collections.api.RichIterable.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
selectWithback to summary
public <P> ImmutableBag<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter)

Implements org.eclipse.collections.api.bag.ImmutableBag.selectWith, org.eclipse.collections.api.bag.ImmutableBagIterable.selectWith, org.eclipse.collections.api.bag.Bag.selectWith, org.eclipse.collections.api.RichIterable.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)

Implements org.eclipse.collections.api.bag.ImmutableBag.tap, org.eclipse.collections.api.bag.ImmutableBagIterable.tap, org.eclipse.collections.api.bag.Bag.tap, org.eclipse.collections.api.RichIterable.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
toImmutableback to summary
public ImmutableBag<T> toImmutable()

Implements org.eclipse.collections.api.bag.Bag.toImmutable.

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

Implements org.eclipse.collections.api.bag.ImmutableBag.topOccurrences, 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