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

public abstract Class AbstractHashBag<T>

extends AbstractMutableBag<T>
Class Inheritance
Known Direct Subclasses
org.eclipse.collections.impl.bag.mutable.HashBag, org.eclipse.collections.impl.bag.strategy.mutable.HashBagWithHashingStrategy
Imports
java.util.Iterator, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.bag.Bag, org.eclipse.collections.api.block.function.Function, org.eclipse.collections.api.block.predicate.Predicate, .Predicate2, org.eclipse.collections.api.block.predicate.primitive.ObjectIntPredicate, org.eclipse.collections.api.block.procedure.Procedure, .Procedure2, org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure, org.eclipse.collections.api.map.MutableMap, org.eclipse.collections.api.map.primitive.MutableObjectIntMap, org.eclipse.collections.api.tuple.primitive.ObjectIntPair, org.eclipse.collections.impl.Counter, org.eclipse.collections.impl.block.factory.primitive.IntToIntFunctions, org.eclipse.collections.impl.map.mutable.UnifiedMap, org.eclipse.collections.impl.multimap.bag.HashBagMultimap, org.eclipse.collections.impl.set.mutable.SetAdapter

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
protected MutableObjectIntMap<T>
protected int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
add(T item)

Implements java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation).

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.

public void
clear()

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).

protected abstract int
public boolean
contains(Object o)

Overrides org.eclipse.collections.impl.AbstractRichIterable.contains.

Implements org.eclipse.collections.api.RichIterable.contains, java.util.Collection.contains.

Returns true if the iterable has an element which responds true to element.equals(object).

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 void
each(Procedure<? super T> procedure)

Implements org.eclipse.collections.api.RichIterable.each.

The procedure is executed for each element in the iterable.

public boolean
equals(Object other)

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 <P> void
forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

public void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex.

Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

public void
forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)

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

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

protected RichIterable<T>
public <V> HashBagMultimap<V, T>
groupBy(Function<? super T, ? extends V> function)

Implements org.eclipse.collections.api.bag.MutableBag.groupBy, org.eclipse.collections.api.bag.MutableBagIterable.groupBy, org.eclipse.collections.api.bag.Bag.groupBy, 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.

public <V> HashBagMultimap<V, T>
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 boolean
public Iterator<T>
iterator()

Implements java.lang.Iterable.iterator, java.util.Collection.iterator.

Returns an iterator over elements of type 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 boolean
remove(Object item)

Implements java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation).

public boolean
public boolean
removeIf(Predicate<? super T> predicate)

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

Removes all elements in the collection that evaluate to true for the specified predicate.

public <P> boolean
removeIfWith(Predicate2<? super T, ? super P> predicate, P parameter)

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

Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.

public boolean
public boolean
public int
size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Collection.size.

Returns the number of items in this iterable.

public int
sizeDistinct()

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

The size of the Bag when counting only distinct elements.

public MutableMap<T, Integer>
Inherited from org.eclipse.collections.impl.bag.mutable.AbstractMutableBag:
asParallelasSynchronizedasUnmodifiablecollectcollectIfcollectWithcollectWithOccurrencescountBycountByEachcountByWithflatCollectpartitionpartitionWithrejectrejectWithselectselectInstancesOfselectWithtaptoImmutablezipzipWithIndex

Field Detail

itemsback to summary
protected MutableObjectIntMap<T> items
sizeback to summary
protected int size

Constructor Detail

AbstractHashBagback to summary
public AbstractHashBag()

Method Detail

addback to summary
public boolean add(T item)

Implements java.util.Collection.add.

Doc from java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

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

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

Doc from org.eclipse.collections.api.bag.MutableBagIterable.addOccurrences.

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));
Annotations
@Override
allSatisfyWithOccurrencesback to summary
public boolean allSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

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

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

Annotations
@Override
anySatisfyWithOccurrencesback to summary
public boolean anySatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

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

Returns true if the predicate evaluates to true for any element of the Bag. Returns false if the Bag is empty or if no element returns true for the predicate.

Annotations
@Override
clearback to summary
public void clear()

Implements java.util.Collection.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

Annotations
@Override
computeHashCodeback to summary
protected abstract int computeHashCode(T item)
containsback to summary
public boolean contains(Object o)

Overrides org.eclipse.collections.impl.AbstractRichIterable.contains.

Implements org.eclipse.collections.api.RichIterable.contains, java.util.Collection.contains.

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

Returns true if the iterable has an element which responds true to element.equals(object).

Annotations
@Override
detectWithOccurrencesback to summary
public T detectWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Doc from 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

Annotations
@Override
distinctViewback to summary
public RichIterable<T> distinctView()

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

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

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

Annotations
@Override
eachback to summary
public void each(Procedure<? super T> procedure)

Implements org.eclipse.collections.api.RichIterable.each.

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

The procedure is executed for each element in the iterable.

Example using a Java 8 lambda expression:

people.each(person -> LOGGER.info(person.getName()));
This method is a variant of InternalIterable#forEach(Procedure) that has a signature conflict with Iterable#forEach(java.util.function.Consumer).
Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

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

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

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

Annotations
@Override
forEachWithback to summary
public <P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWith.

Implements org.eclipse.collections.api.InternalIterable.forEachWith.

Doc from org.eclipse.collections.api.InternalIterable.forEachWith.

The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

Example using a Java 8 lambda:

people.forEachWith((Person person, Person other) ->
    {
        if (person.isRelatedTo(other))
        {
             LOGGER.info(person.getName());
        }
    }, fred);

Example using an anonymous inner class:

people.forEachWith(new Procedure2<Person, Person>()
{
    public void value(Person person, Person other)
    {
        if (person.isRelatedTo(other))
        {
             LOGGER.info(person.getName());
        }
    }
}, fred);
Annotations
@Override
forEachWithIndexback to summary
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)

Overrides org.eclipse.collections.impl.AbstractRichIterable.forEachWithIndex.

Implements org.eclipse.collections.api.InternalIterable.forEachWithIndex.

Doc from org.eclipse.collections.api.InternalIterable.forEachWithIndex.

Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

Example using a Java 8 lambda:

people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));

Example using an anonymous inner class:

people.forEachWithIndex(new ObjectIntProcedure<Person>()
{
    public void value(Person person, int index)
    {
        LOGGER.info("Index: " + index + " person: " + person.getName());
    }
});
Annotations
@Override
forEachWithOccurrencesback to summary
public void forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)

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

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

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

Annotations
@Override
getKeysViewback to summary
protected RichIterable<T> getKeysView()

Implements abstract org.eclipse.collections.impl.bag.mutable.AbstractMutableBagIterable.getKeysView.

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

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

Implements org.eclipse.collections.api.bag.MutableBag.groupByEach, org.eclipse.collections.api.bag.MutableBagIterable.groupByEach, org.eclipse.collections.api.bag.Bag.groupByEach, org.eclipse.collections.api.RichIterable.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
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

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

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

Returns the hash code for this Bag, defined as this.toMapOfItemToCount().hashCode().

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides org.eclipse.collections.impl.AbstractRichIterable.isEmpty.

Implements org.eclipse.collections.api.RichIterable.isEmpty, java.util.Collection.isEmpty.

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

Returns true if this iterable has zero items.

Annotations
@Override
iteratorback to summary
public Iterator<T> iterator()

Implements java.lang.Iterable.iterator, java.util.Collection.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Annotations
@Override
noneSatisfyWithOccurrencesback to summary
public boolean noneSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)

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

Doc from 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. Returns false if the predicate evaluates to true for at least one element of the Bag.

Annotations
@Override
occurrencesOfback to summary
public int occurrencesOf(Object item)

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

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

The occurrences of a distinct item in the bag.

Annotations
@Override
removeback to summary
public boolean remove(Object item)

Implements java.util.Collection.remove.

Doc from java.util.Collection.remove.

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that Objects.equals(o, e), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

Annotations
@Override
removeAllIterableback to summary
public boolean removeAllIterable(Iterable<?> iterable)

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

Annotations
@Override
removeIfback to summary
public boolean removeIf(Predicate<? super T> predicate)

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

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

Removes all elements in the collection that evaluate to true for the specified predicate.

e.g.
return lastNames.removeIf(Predicates.isNull());
Annotations
@Override
removeIfWithback to summary
public <P> boolean removeIfWith(Predicate2<? super T, ? super P> predicate, P parameter)

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

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

Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.

return lastNames.removeIfWith(Predicates2.isNull(), null);
Annotations
@Override
removeOccurrencesback to summary
public boolean removeOccurrences(Object item, int occurrences)

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

Annotations
@Override
setOccurrencesback to summary
public boolean setOccurrences(T item, int occurrences)

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

Annotations
@Override
sizeback to summary
public int size()

Implements org.eclipse.collections.api.RichIterable.size, java.util.Collection.size.

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

Returns the number of items in this iterable.

Annotations
@Override
sizeDistinctback to summary
public int sizeDistinct()

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

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

The size of the Bag when counting only distinct elements.

Annotations
@Override
toMapOfItemToCountback to summary
public MutableMap<T, Integer> toMapOfItemToCount()

Implements org.eclipse.collections.api.bag.MutableBag.toMapOfItemToCount, org.eclipse.collections.api.bag.MutableBagIterable.toMapOfItemToCount, 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
org.eclipse.collections.impl.bag.mutable back to summary

private Class AbstractHashBag.InternalIterator

extends Object
implements Iterator<T>
Class Inheritance
  • java.lang.Object
  • org.eclipse.collections.impl.bag.mutable.AbstractHashBag.InternalIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private boolean
private T
private final Iterator<T>
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canRemoveback to summary
private boolean canRemove
currentItemback to summary
private T currentItem
iteratorback to summary
private final Iterator<T> iterator
occurrencesback to summary
private int occurrences

Constructor Detail

InternalIteratorback to summary
private InternalIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Annotations
@Override
nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override