Iterable<T>, Collection<T>, Bag<T>, MutableBag<T>, MutableBagIterable<T>, UnsortedBag<T>, MutableCollection<T>, InternalIterable<T>, RichIterable<T>HashBag, HashBagWithHashingStrategypublic 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 bagsb1 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) |
|
abstract MutableBag<T> |
selectByOccurrences(IntPredicate predicate) |
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.
|
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, toStringOfItemToCountasParallel, asSynchronized, asUnmodifiable, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, flatCollect, partition, partitionWith, reject, rejectWith, select, selectInstancesOf, selectWith, tap, toImmutable, zip, zipWithIndexaddAll, 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, topOccurrencesappendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, forEach, groupByUniqueKey, into, toArray, toArray, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedSetBy, toString, zip, zipWithIndexreduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCountaddAll, containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArrayforEachnewEmpty, with, withAll, without, withoutAllbottomOccurrences, topOccurrencesaddAllIterable, aggregateBy, aggregateInPlaceBy, groupByUniqueKey, injectIntoWith, retainAllIterable, selectAndRejectWith, sumByDouble, sumByFloat, sumByInt, sumByLongallSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, flatCollect, getFirst, getLast, getOnly, groupBy, 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, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexpublic int addOccurrences(T item, int occurrences)
MutableBagIterableoccurrences 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)
Bagequals in interface Bag<T>equals in interface Collection<T>equals in class ObjectMap.equals(Object)public int hashCode()
BagBag.toMapOfItemToCount().hashCode().hashCode in interface Bag<T>hashCode in interface Collection<T>hashCode in class ObjectMap.hashCode()public abstract MutableBag<T> selectByOccurrences(IntPredicate predicate)
Bagpublic int sizeDistinct()
Bagpublic int occurrencesOf(Object item)
Bagpublic void forEachWithOccurrences(ObjectIntProcedure<? super T> objectIntProcedure)
Bagpublic MutableMap<T,Integer> toMapOfItemToCount()
Bagpublic boolean add(T item)
public boolean remove(Object item)
public void clear()
public boolean isEmpty()
RichIterableisEmpty in interface Collection<T>isEmpty in interface RichIterable<T>isEmpty in class AbstractRichIterable<T>public void each(Procedure<? super T> procedure)
RichIterableExample 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)
InternalIterableExample 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)
InternalIterableExample 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()
RichIterablepublic boolean contains(Object o)
RichIterablecontains 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)
RichIterableExample 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)
RichIterableRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys
for each value.Copyright © 2004–2017. All rights reserved.