Iterable<T>
, Collection<T>
, Bag<T>
, MutableBag<T>
, MutableBagIterable<T>
, UnsortedBag<T>
, MutableCollection<T>
, InternalIterable<T>
, RichIterable<T>
HashBag
, HashBagWithHashingStrategy
public abstract class AbstractHashBag<T> extends AbstractMutableBag<T>
Constructor | Description |
---|---|
AbstractHashBag() |
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(T item) |
|
int |
addOccurrences(T item,
int occurrences) |
Add number of
occurrences for an item . |
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 bags
b1 and b2 are equal if m1.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 to
RichIterable.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.
|
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, count, flatCollect, 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
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
addAll, addAllIterable, aggregateBy, 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
appendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, forEach, groupByUniqueKey, into, toArray, toArray, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, zip, zipWithIndex
collectWithOccurrences, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
addAll, containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
forEach
flatCollectWith, newEmpty, selectByOccurrences, selectDuplicates, selectUnique, with, withAll, without, withoutAll
bottomOccurrences, topOccurrences
addAllIterable, aggregateBy, aggregateInPlaceBy, groupByUniqueKey, injectIntoWith, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLong
allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countBy, countByEach, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, 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
public int addOccurrences(T item, int occurrences)
MutableBagIterable
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));
public boolean equals(Object other)
Bag
b1
and b2
are equal if m1.toMapOfItemToCount().equals(m2.toMapOfItemToCount())
.equals
in interface Bag<T>
equals
in interface Collection<T>
equals
in class Object
Map.equals(Object)
public int hashCode()
Bag
Bag.toMapOfItemToCount()
.hashCode().hashCode
in interface Bag<T>
hashCode
in interface Collection<T>
hashCode
in class Object
Map.hashCode()
public int sizeDistinct()
Bag
public int occurrencesOf(Object item)
Bag
public void forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)
Bag
public MutableMap<T,Integer> toMapOfItemToCount()
Bag
public boolean add(T item)
public boolean remove(Object item)
public void clear()
public boolean isEmpty()
RichIterable
isEmpty
in interface Collection<T>
isEmpty
in interface RichIterable<T>
isEmpty
in class AbstractRichIterable<T>
public void each(Procedure<? super T> procedure)
RichIterable
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 of
InternalIterable.forEach(Procedure)
that has a signature conflict with Iterable.forEach(java.util.function.Consumer)
.public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
InternalIterable
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()); } });
forEachWithIndex
in interface InternalIterable<T>
forEachWithIndex
in class AbstractRichIterable<T>
public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
InternalIterable
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);
forEachWith
in interface InternalIterable<T>
forEachWith
in class AbstractRichIterable<T>
public boolean removeOccurrences(Object item, int occurrences)
public boolean setOccurrences(T item, int occurrences)
public boolean removeIf(Predicate<? super T> predicate)
MutableCollection
e.g. return lastNames.removeIf(Predicates.isNull());
public <P> boolean removeIfWith(Predicate2<? super T,? super P> predicate, P parameter)
MutableCollection
return lastNames.removeIfWith(Predicates2.isNull(), null);
public boolean removeAllIterable(Iterable<?> iterable)
Collection.removeAll(Collection)
public int size()
RichIterable
public boolean contains(Object o)
RichIterable
contains
in interface Collection<T>
contains
in interface RichIterable<T>
contains
in class AbstractRichIterable<T>
public <V> HashBagMultimap<V,T> groupBy(Function<? super T,? extends V> function)
RichIterable
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(); } });
public <V> HashBagMultimap<V,T> groupByEach(Function<? super T,? extends Iterable<V>> function)
RichIterable
RichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys
for each value.Copyright © 2004–2019. All rights reserved.