Class AbstractHashBag<T>
java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<T>
org.eclipse.collections.impl.bag.AbstractBag<T>
org.eclipse.collections.impl.bag.mutable.AbstractMutableBagIterable<T>
org.eclipse.collections.impl.bag.mutable.AbstractMutableBag<T>
org.eclipse.collections.impl.bag.mutable.AbstractHashBag<T>
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Bag<T>
,MutableBag<T>
,MutableBagIterable<T>
,UnsortedBag<T>
,MutableCollection<T>
,InternalIterable<T>
,RichIterable<T>
- Direct Known Subclasses:
HashBag
,HashBagWithHashingStrategy
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
addOccurrences
(T item, int occurrences) Add number ofoccurrences
for anitem
.boolean
allSatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for all elements of the Bag.boolean
anySatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the predicate evaluates to true for any element of the Bag.void
clear()
boolean
Returns true if the iterable has an element which responds true to element.equals(object).detectWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns an element of the Bag that satisfies the predicate or null if such an element does not existReturns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.void
The procedure is executed for each element in the iterable.boolean
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.<P> void
forEachWith
(Procedure2<? super T, ? super P> procedure, P parameter) The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.void
forEachWithIndex
(ObjectIntProcedure<? super T> objectIntProcedure) Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.void
forEachWithOccurrences
(ObjectIntProcedure<? super T> objectIntProcedure) For each distinct item, with the number of occurrences, execute the specified procedure.<V> HashBagMultimap<V,
T> 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.<V> HashBagMultimap<V,
T> groupByEach
(Function<? super T, ? extends Iterable<V>> function) Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.int
hashCode()
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().boolean
isEmpty()
Returns true if this iterable has zero items.iterator()
boolean
noneSatisfyWithOccurrences
(ObjectIntPredicate<? super T> predicate) Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag.int
occurrencesOf
(Object item) The occurrences of a distinct item in the bag.boolean
boolean
removeAllIterable
(Iterable<?> iterable) boolean
Removes all elements in the collection that evaluate to true for the specified predicate.<P> boolean
removeIfWith
(Predicate2<? super T, ? super P> predicate, P parameter) Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.boolean
removeOccurrences
(Object item, int occurrences) boolean
setOccurrences
(T item, int occurrences) int
size()
Returns the number of items in this iterable.int
The size of the Bag when counting only distinct elements.Converts the Bag to a Map of the Item type to its count as an Integer.Methods inherited from class org.eclipse.collections.impl.bag.mutable.AbstractMutableBag
asParallel, asSynchronized, asUnmodifiable, collect, collectIf, collectWith, collectWithOccurrences, countBy, countByEach, countByWith, flatCollect, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, tap, toImmutable, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.bag.mutable.AbstractMutableBagIterable
addAll, addAllIterable, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, bottomOccurrences, chunk, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, getFirst, getLast, groupByUniqueKey, max, max, maxBy, min, min, minBy, noneSatisfy, noneSatisfyWith, removeAll, retainAll, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, topOccurrences
Methods inherited from class org.eclipse.collections.impl.bag.AbstractBag
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, count, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toSet, toSortedBag, toSortedBag, toSortedList, toSortedSet, toSortedSet, toStringOfItemToCount
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, forEach, groupByUniqueKey, into, toArray, toArray, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
Methods inherited from interface java.util.Collection
addAll, containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
Methods inherited from interface org.eclipse.collections.api.bag.MutableBag
collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, flatCollectWith, newEmpty, selectByOccurrences, selectDuplicates, selectUnique, toImmutableBag, with, withAll, without, withoutAll
Methods inherited from interface org.eclipse.collections.api.bag.MutableBagIterable
bottomOccurrences, selectByOccurrences, selectDuplicates, selectUnique, topOccurrences
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
addAllIterable, aggregateBy, aggregateInPlaceBy, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, flatCollectWith, groupByUniqueKey, injectIntoWith, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.RichIterable
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getFirst, getLast, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
Constructor Details
-
AbstractHashBag
public AbstractHashBag()
-
-
Method Details
-
addOccurrences
Description copied from interface:MutableBagIterable
Add number ofoccurrences
for anitem
. If theitem
does not exist, then theitem
is added to the bag.For Example:
MutableBagIterable<String> names = Bags.mutable.of("A", "B", "B"); Assert.assertEquals(4, names.addOccurrences("A", 3));
- Returns:
- updated number of occurrences.
-
equals
Description copied from interface:Bag
Two bagsb1
andb2
are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
. -
hashCode
public int hashCode()Description copied from interface:Bag
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode(). -
sizeDistinct
public int sizeDistinct()Description copied from interface:Bag
The size of the Bag when counting only distinct elements. -
occurrencesOf
Description copied from interface:Bag
The occurrences of a distinct item in the bag. -
forEachWithOccurrences
Description copied from interface:Bag
For each distinct item, with the number of occurrences, execute the specified procedure. -
anySatisfyWithOccurrences
Description copied from interface:Bag
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. -
allSatisfyWithOccurrences
Description copied from interface:Bag
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. -
noneSatisfyWithOccurrences
Description copied from interface:Bag
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. -
detectWithOccurrences
Description copied from interface:Bag
Returns an element of the Bag that satisfies the predicate or null if such an element does not exist -
toMapOfItemToCount
Description copied from interface:Bag
Converts the Bag to a Map of the Item type to its count as an Integer. -
add
-
remove
-
clear
public void clear() -
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceRichIterable<T>
- Overrides:
isEmpty
in classAbstractRichIterable<T>
-
each
Description copied from interface:RichIterable
The procedure is executed for each element in the iterable.Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
people.each(new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This method is a variant ofInternalIterable.forEach(Procedure)
that has a signature conflict withIterable.forEach(java.util.function.Consumer)
. -
forEachWithIndex
Description copied from interface:InternalIterable
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()); } });
- Specified by:
forEachWithIndex
in interfaceInternalIterable<T>
- Overrides:
forEachWithIndex
in classAbstractRichIterable<T>
-
forEachWith
Description copied from interface:InternalIterable
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);
- Specified by:
forEachWith
in interfaceInternalIterable<T>
- Overrides:
forEachWith
in classAbstractRichIterable<T>
-
iterator
-
removeOccurrences
-
setOccurrences
-
removeIf
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate.e.g. return lastNames.removeIf(Predicates.isNull());
-
removeIfWith
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.return lastNames.removeIfWith(Predicates2.isNull(), null);
-
removeAllIterable
- See Also:
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable. -
contains
Description copied from interface:RichIterable
Returns true if the iterable has an element which responds true to element.equals(object).- Specified by:
contains
in interfaceCollection<T>
- Specified by:
contains
in interfaceRichIterable<T>
- Overrides:
contains
in classAbstractRichIterable<T>
-
groupBy
Description copied from interface:RichIterable
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);
Example using an anonymous inner class:
Multimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } });
-
groupByEach
Description copied from interface:RichIterable
Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value. -
distinctView
Description copied from interface:Bag
Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.- Returns:
- an unmodifiable view on the distinct elements of the Bag.
-