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
public abstract class AbstractHashBag<T> extends AbstractMutableBag<T>
-
Constructor Summary
Constructors Constructor Description AbstractHashBag()
-
Method Summary
Modifier and Type Method Description boolean
add(T item)
int
addOccurrences(T item, int occurrences)
Add number ofoccurrences
for anitem
.void
clear()
boolean
contains(Object o)
Returns true if the iterable has an element which responds true to element.equals(object).void
each(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.boolean
equals(Object other)
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>
groupBy(Function<? super T,? extends V> function)
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<T>
iterator()
int
occurrencesOf(Object item)
The occurrences of a distinct item in the bag.boolean
remove(Object item)
boolean
removeAllIterable(Iterable<?> iterable)
boolean
removeIf(Predicate<? super T> predicate)
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
sizeDistinct()
The size of the Bag when counting only distinct elements.MutableMap<T,Integer>
toMapOfItemToCount()
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, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, 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, aggregateInPlaceBy, 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.bag.MutableBag
flatCollectWith, newEmpty, selectByOccurrences, selectDuplicates, selectUnique, 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, 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, containsBy, 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, into, 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, 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())
.- Specified by:
equals
in interfaceBag<T>
- Specified by:
equals
in interfaceCollection<T>
- Overrides:
equals
in classObject
- See Also:
Map.equals(Object)
-
hashCode
public int hashCode()Description copied from interface:Bag
Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount()
.hashCode().- Specified by:
hashCode
in interfaceBag<T>
- Specified by:
hashCode
in interfaceCollection<T>
- Overrides:
hashCode
in classObject
- See Also:
Map.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. -
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:
Collection.removeAll(Collection)
-
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.
-