Top Description Inners Fields Constructors Methods
org.eclipse.collections.impl.bag.mutable

public final Class MultiReaderHashBag<T>

extends AbstractMultiReaderMutableCollection<T>
implements Externalizable, MultiReaderBag<T>
Class Inheritance
All Implemented Interfaces
org.eclipse.collections.api.bag.MultiReaderBag, org.eclipse.collections.api.bag.MutableBag, org.eclipse.collections.api.bag.MutableBagIterable, org.eclipse.collections.api.collection.MutableCollection, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.InternalIterable, java.lang.Iterable, java.util.Collection, org.eclipse.collections.api.bag.Bag, org.eclipse.collections.api.bag.UnsortedBag, java.io.Externalizable, java.io.Serializable
Imports
java.io.Externalizable, .IOException, .ObjectInput, .ObjectOutput, java.util.Collection, .Iterator, java.util.concurrent.locks.ReadWriteLock, .ReentrantReadWriteLock, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.bag.ImmutableBag, .MultiReaderBag, .MutableBag, org.eclipse.collections.api.bag.primitive.MutableBooleanBag, .MutableByteBag, .MutableCharBag, .MutableDoubleBag, .MutableFloatBag, .MutableIntBag, .MutableLongBag, .MutableShortBag, 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, .ObjectIntPredicate, org.eclipse.collections.api.block.procedure.Procedure, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure, org.eclipse.collections.api.factory.Bags, org.eclipse.collections.api.factory.primitive.ObjectLongMaps, org.eclipse.collections.api.list.MutableList, org.eclipse.collections.api.map.MutableMap, org.eclipse.collections.api.map.primitive.MutableObjectLongMap, org.eclipse.collections.api.multimap.bag.MutableBagMultimap, org.eclipse.collections.api.ordered.OrderedIterable, org.eclipse.collections.api.partition.bag.PartitionMutableBag, org.eclipse.collections.api.set.MutableSet, org.eclipse.collections.api.tuple.Pair, org.eclipse.collections.api.tuple.primitive.ObjectIntPair, org.eclipse.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection, org.eclipse.collections.impl.factory.Iterables

MultiReaderHashBag provides a thread-safe wrapper around a HashBag, using a ReentrantReadWriteLock. In order to provide true thread-safety, MultiReaderHashBag does not implement iterator() as this method requires an external lock to be taken to provide thread-safe iteration. All of these methods are available however, if you use the withReadLockAndDelegate() or withWriteLockAndDelegate() methods. Both of these methods take a parameter of type Procedure<MutableBag>, and a wrapped version of the underlying HashBag is returned. This wrapper guarantees that no external pointer can ever reference the underlying HashBag outside a locked procedure. In the case of the read lock method, an Unmodifiable version of the collection is offered, which will throw UnsupportedOperationExceptions on any write methods like add or remove.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private HashBag<T>
private static final long
Inherited from org.eclipse.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection:
locklockWrapper

Constructor Summary

AccessConstructor and Description
public
MultiReaderHashBag()
Deprecated Empty default constructor used for serialization.

private
MultiReaderHashBag(HashBag<T> newDelegate)

private
MultiReaderHashBag(HashBag<T> newDelegate, ReadWriteLock newLock)

Method Summary

Modifier and TypeMethod and Description
public int
addOccurrences(T item, int occurrences)

Implements org.eclipse.collections.api.bag.MutableBagIterable.addOccurrences.

Add number of occurrences for an item.

public boolean
allSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Returns true if the predicate evaluates to true for all elements of the Bag.

public boolean
anySatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Returns true if the predicate evaluates to true for any element of the Bag.

pack-priv MultiReaderHashBag.UntouchableMutableBag<T>
public MutableBag<T>
public MutableBag<T>
pack-priv MultiReaderHashBag.UntouchableMutableBag<T>
public MutableList<ObjectIntPair<T>>
public RichIterable<RichIterable<T>>
chunk(int size)

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

Partitions elements in fixed size chunks.

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

Implements org.eclipse.collections.api.bag.MutableBag.collect, org.eclipse.collections.api.collection.MutableCollection.collect.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectBoolean, org.eclipse.collections.api.collection.MutableCollection.collectBoolean.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectByte, org.eclipse.collections.api.collection.MutableCollection.collectByte.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectChar, org.eclipse.collections.api.collection.MutableCollection.collectChar.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectDouble, org.eclipse.collections.api.collection.MutableCollection.collectDouble.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectFloat, org.eclipse.collections.api.collection.MutableCollection.collectFloat.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.collectIf, org.eclipse.collections.api.collection.MutableCollection.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 MutableIntBag
collectInt(IntFunction<? super T> intFunction)

Overrides default org.eclipse.collections.api.bag.MutableBag.collectInt, org.eclipse.collections.api.collection.MutableCollection.collectInt.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectLong, org.eclipse.collections.api.collection.MutableCollection.collectLong.

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

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

Overrides default org.eclipse.collections.api.bag.MutableBag.collectShort, org.eclipse.collections.api.collection.MutableCollection.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> MutableBag<V>
collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter)

Implements org.eclipse.collections.api.bag.MutableBag.collectWith, org.eclipse.collections.api.collection.MutableCollection.collectWith.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.collectWithOccurrences.

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

public <V, R extends Collection<V>> R
collectWithOccurrences(ObjectIntToObjectFunction<? super T, ? extends V> function, R target)

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

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

public T
detectWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Returns an element of the Bag that satisfies the predicate or null if such an element does not exist

public RichIterable<T>
distinctView()

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

Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Implements org.eclipse.collections.api.bag.Bag.equals, java.util.Collection.equals.

Two bags b1 and b2 are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).

public <V> MutableBag<V>
public void
forEachWithOccurrences(ObjectIntProcedure<? super T> procedure)

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

For each distinct item, with the number of occurrences, execute the specified procedure.

protected MutableBag<T>
public <V> MutableBagMultimap<V, T>
groupBy(Function<? super T, ? extends V> function)

Implements org.eclipse.collections.api.bag.MutableBag.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> MutableBagMultimap<V, T>
groupByEach(Function<? super T, ? extends Iterable<V>> function)

Implements org.eclipse.collections.api.bag.MutableBag.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 <V> MutableMap<V, T>
groupByUniqueKey(Function<? super T, ? extends V> function)

Overrides default org.eclipse.collections.api.collection.MutableCollection.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 int
hashCode()

Overrides java.lang.Object.hashCode.

Implements org.eclipse.collections.api.bag.Bag.hashCode, java.util.Collection.hashCode.

Returns the hash code for this Bag, defined as this.

public static <T> MultiReaderHashBag<T>
public static <T> MultiReaderHashBag<T>
newBag(int capacity)

public static <T> MultiReaderHashBag<T>
newBag(Iterable<T> iterable)

public static <T> MultiReaderHashBag<T>
newBagWith(T... elements)

public MultiReaderBag<T>
public boolean
noneSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag.

public int
occurrencesOf(Object item)

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

The occurrences of a distinct item in the bag.

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

Implements org.eclipse.collections.api.bag.MutableBag.partition, org.eclipse.collections.api.collection.MutableCollection.partition.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.partitionWith, org.eclipse.collections.api.collection.MutableCollection.partitionWith.

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

public void
readExternal(ObjectInput in)

Implements java.io.Externalizable.readExternal.

The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.

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

Implements org.eclipse.collections.api.bag.MutableBag.reject, org.eclipse.collections.api.collection.MutableCollection.reject.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.rejectWith, org.eclipse.collections.api.collection.MutableCollection.rejectWith.

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

public boolean
public MutableBag<T>
select(Predicate<? super T> predicate)

Implements org.eclipse.collections.api.bag.MutableBag.select, org.eclipse.collections.api.collection.MutableCollection.select.

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

public MutableBag<T>
selectByOccurrences(IntPredicate predicate)

Implements org.eclipse.collections.api.bag.MutableBag.selectByOccurrences.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.selectInstancesOf, org.eclipse.collections.api.collection.MutableCollection.selectInstancesOf.

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

public MutableSet<T>
selectUnique()

Overrides default org.eclipse.collections.api.bag.MutableBag.selectUnique.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.selectWith, org.eclipse.collections.api.collection.MutableCollection.selectWith.

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

public boolean
public int
sizeDistinct()

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

The size of the Bag when counting only distinct elements.

public <V> MutableObjectLongMap<V>
public <V> MutableObjectLongMap<V>
public MultiReaderBag<T>
tap(Procedure<? super T> procedure)

Overrides default org.eclipse.collections.api.bag.MultiReaderBag.tap.

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

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

public ImmutableBag<T>
public MutableMap<T, Integer>
toMapOfItemToCount()

Implements org.eclipse.collections.api.bag.MutableBag.toMapOfItemToCount.

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

public MutableList<ObjectIntPair<T>>
public String
toStringOfItemToCount()

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

Returns a string representation of this bag.

public void
trimToSize()

Rehashes every element in the set into a new backing table of the smallest possible size and eliminating removed sentinels.

public void
public void
public void
writeExternal(ObjectOutput out)

Implements java.io.Externalizable.writeExternal.

The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

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

Implements org.eclipse.collections.api.bag.MutableBag.zip, org.eclipse.collections.api.collection.MutableCollection.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 MutableSet<Pair<T, Integer>>
Inherited from org.eclipse.collections.impl.collection.mutable.AbstractMultiReaderMutableCollection:
addaddAlladdAllIterableaggregateInPlaceByallSatisfyallSatisfyWithanySatisfyanySatisfyWithappendStringappendStringappendStringasLazyclearcollectcollectBooleancollectBytecollectCharcollectDoublecollectFloatcollectIfcollectIntcollectLongcollectShortcollectWithcontainscontainsAllcontainsAllArgumentscontainsAllIterablecountcountWithdetectdetectIfNonedetectOptionaldetectWithdetectWithIfNonedetectWithOptionaleachflatCollectflatCollectBooleanflatCollectByteflatCollectCharflatCollectDoubleflatCollectFloatflatCollectIntflatCollectLongflatCollectShortforEachWithforEachWithIndexgetFirstgetLastgetOnlygroupBygroupByEachgroupByUniqueKeyinjectIntoinjectIntoinjectIntoinjectIntoinjectIntoinjectIntoWithintoisEmptyiteratormakeStringmakeStringmakeStringmakeStringmaxmaxmaxBymaxByOptionalmaxOptionalmaxOptionalminminminByminByOptionalminOptionalminOptionalnoneSatisfynoneSatisfyWithnotEmptyparallelStreamreduceByreduceByrejectrejectWithremoveremoveAllremoveAllIterableremoveIfremoveIfWithretainAllretainAllIterableselectselectAndRejectWithselectWithsizespliteratorstreamsumByDoublesumByFloatsumOfDoublesumOfFloatsumOfIntsumOfLongtoArraytoArraytoBagtoBiMaptoImmutableBagtoImmutableListtoImmutableSettoImmutableSortedBagtoImmutableSortedBagtoImmutableSortedBagBytoImmutableSortedListtoImmutableSortedListtoImmutableSortedListBytoImmutableSortedSettoImmutableSortedSettoImmutableSortedSetBytoListtoMaptoMaptoSettoSortedBagtoSortedBagtoSortedListtoSortedListtoSortedListBytoSortedMaptoSortedMaptoSortedSettoSortedSettoSortedSetBytoStringzipzipWithIndex