java.lang.Iterable<V>, InternalIterable<V>, MapIterable<K,V>, RichIterable<V>AbstractImmutableMap, AbstractImmutableSortedMap, AbstractMutableMapIterable, OrderedMapAdapterpublic abstract class AbstractMapIterable<K,V> extends AbstractRichIterable<V> implements MapIterable<K,V>
| Constructor | Description |
|---|---|
AbstractMapIterable() |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
allSatisfy(Predicate<? super V> predicate) |
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.
|
<P> boolean |
allSatisfyWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to true for every element of the collection, or returns false.
|
boolean |
anySatisfy(Predicate<? super V> predicate) |
Returns true if the predicate evaluates to true for any element of the iterable.
|
<P> boolean |
anySatisfyWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to true for any element of the collection, or return false.
|
LazyIterable<V> |
asLazy() |
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).
|
RichIterable<RichIterable<V>> |
chunk(int size) |
Partitions elements in fixed size chunks.
|
boolean |
contains(java.lang.Object object) |
Returns true if the iterable has an element which responds true to element.equals(object).
|
V |
detect(Predicate<? super V> predicate) |
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no
element returns true.
|
V |
detectIfNone(Predicate<? super V> predicate,
Function0<? extends V> function) |
Returns the first element of the iterable for which the predicate evaluates to true.
|
java.util.Optional<V> |
detectOptional(Predicate<? super V> predicate) |
Returns the first element of the iterable for which the predicate evaluates to true as an Optional.
|
<P> V |
detectWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none
evaluate to true.
|
<P> V |
detectWithIfNone(Predicate2<? super V,? super P> predicate,
P parameter,
Function0<? extends V> function) |
Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or
returns the value of evaluating the specified function.
|
<P> java.util.Optional<V> |
detectWithOptional(Predicate2<? super V,? super P> predicate,
P parameter) |
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.
|
void |
each(Procedure<? super V> procedure) |
The procedure is executed for each element in the iterable.
|
void |
forEachKey(Procedure<? super K> procedure) |
Calls the
procedure with each key of the map. |
void |
forEachValue(Procedure<? super V> procedure) |
Calls the procedure with each value of the map.
|
<P> void |
forEachWith(Procedure2<? super V,? super P> procedure2,
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 V> objectIntProcedure) |
Iterates over the iterable passing each element and the current relative int index to the specified instance of
ObjectIntProcedure.
|
V |
getFirst() |
Returns the first element of an iterable.
|
V |
getIfAbsent(K key,
Function0<? extends V> function) |
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the
result of evaluating the specified Function0.
|
V |
getIfAbsentValue(K key,
V value) |
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return
value. |
<P> V |
getIfAbsentWith(K key,
Function<? super P,? extends V> function,
P parameter) |
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the
result of evaluating the specified function and parameter.
|
V |
getLast() |
Returns the last element of an iterable.
|
V |
getOnly() |
Returns the element if the iterable has exactly one element.
|
<A> A |
ifPresentApply(K key,
Function<? super V,? extends A> function) |
If there is a value in the Map that corresponds to the specified key return the result of applying the specified
Function on the value, otherwise return null.
|
boolean |
noneSatisfy(Predicate<? super V> predicate) |
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.
|
<P> boolean |
noneSatisfyWith(Predicate2<? super V,? super P> predicate,
P parameter) |
Returns true if the predicate evaluates to false for every element of the collection, or return false.
|
java.lang.Object[] |
toArray() |
Converts this iterable to an array.
|
<T> T[] |
toArray(T[] a) |
Converts this iterable to an array using the specified target array, assuming the target array is as long
or longer than the iterable.
|
appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countByEach, countWith, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, max, max, maxBy, min, min, minBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndexforEachcollect, collectValues, containsKey, containsValue, detect, detectOptional, equals, flip, flipUniqueValues, forEachKeyValue, get, hashCode, keysView, keyValuesView, parallelStream, reject, select, spliterator, stream, tap, toImmutable, toString, valuesViewequals, getClass, hashCode, notify, notifyAll, wait, wait, waitaggregateBy, aggregateInPlaceBy, appendString, appendString, appendString, collect, collect, collectBoolean, collectBoolean, collectByte, collectByte, collectChar, collectChar, collectDouble, collectDouble, collectFloat, collectFloat, collectIf, collectIf, collectInt, collectInt, collectLong, collectLong, collectShort, collectShort, collectWith, collectWith, containsAll, containsAllArguments, containsAllIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, flatCollect, flatCollect, flatCollectWith, flatCollectWith, forEach, getAny, groupBy, groupBy, groupByAndCollect, groupByEach, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, max, max, maxBy, maxByOptional, maxOptional, maxOptional, min, min, minBy, minByOptional, minOptional, minOptional, notEmpty, partition, partitionWith, reduce, reduceInPlace, reduceInPlace, reject, reject, rejectWith, rejectWith, select, select, selectInstancesOf, selectWith, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zip, zipWithIndex, zipWithIndexpublic <A> A ifPresentApply(K key, Function<? super V,? extends A> function)
MapIterableifPresentApply in interface MapIterable<K,V>public V getIfAbsent(K key, Function0<? extends V> function)
MapIterablegetIfAbsent in interface MapIterable<K,V>public V getIfAbsentValue(K key, V value)
MapIterablevalue.getIfAbsentValue in interface MapIterable<K,V>public <P> V getIfAbsentWith(K key, Function<? super P,? extends V> function, P parameter)
MapIterablegetIfAbsentWith in interface MapIterable<K,V>public boolean anySatisfy(Predicate<? super V> predicate)
RichIterableanySatisfy in interface RichIterable<K>anySatisfy in class AbstractRichIterable<V>public <P> boolean anySatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterableanySatisfyWith in interface RichIterable<K>anySatisfyWith in class AbstractRichIterable<V>public boolean allSatisfy(Predicate<? super V> predicate)
RichIterableallSatisfy in interface RichIterable<K>allSatisfy in class AbstractRichIterable<V>public <P> boolean allSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterableallSatisfyWith in interface RichIterable<K>allSatisfyWith in class AbstractRichIterable<V>public boolean noneSatisfy(Predicate<? super V> predicate)
RichIterablenoneSatisfy in interface RichIterable<K>noneSatisfy in class AbstractRichIterable<V>public <P> boolean noneSatisfyWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterablenoneSatisfyWith in interface RichIterable<K>noneSatisfyWith in class AbstractRichIterable<V>public LazyIterable<V> asLazy()
RichIterableasLazy in interface RichIterable<K>asLazy in class AbstractRichIterable<V>public RichIterable<RichIterable<V>> chunk(int size)
RichIterablechunk in interface RichIterable<K>size - the number of elements per chunkRichIterable containing RichIterables of size size, except the last will be
truncated if the elements don't divide evenly.public void each(Procedure<? super V> 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).each in interface RichIterable<K>InternalIterable.forEach(Procedure),
Iterable.forEach(java.util.function.Consumer)public <P> void forEachWith(Procedure2<? super V,? super P> procedure2, 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<K>forEachWith in class AbstractRichIterable<V>public void forEachWithIndex(ObjectIntProcedure<? super V> 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<K>forEachWithIndex in class AbstractRichIterable<V>public void forEachKey(Procedure<? super K> procedure)
MapIterableprocedure with each key of the map.
final Collection<Integer> result = new ArrayList<Integer>();
MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
map.forEachKey(new CollectionAddProcedure<Integer>(result));
Verify.assertContainsAll(result, 1, 2, 3);
forEachKey in interface MapIterable<K,V>public void forEachValue(Procedure<? super V> procedure)
MapIterable
Set<String> result = UnifiedSet.newSet();
MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
map.forEachValue(new CollectionAddProcedure<String>(result));
Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
forEachValue in interface MapIterable<K,V>public boolean contains(java.lang.Object object)
RichIterablecontains in interface RichIterable<K>contains in class AbstractRichIterable<V>public V detect(Predicate<? super V> predicate)
RichIterableExample using a Java 8 lambda expression:
Person person =
people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
Example using an anonymous inner class:
Person person =
people.detect(new Predicate<Person>()
{
public boolean accept(Person person)
{
return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
}
});
detect in interface RichIterable<K>detect in class AbstractRichIterable<V>public <P> V detectWith(Predicate2<? super V,? super P> predicate, P parameter)
RichIterableExample using a Java 8 lambda expression:
Person person =
people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
Example using an anonymous inner class:
Person person =
people.detectWith(new Predicate2<Person, String>()
{
public boolean accept(Person person, String fullName)
{
return person.getFullName().equals(fullName);
}
}, "John Smith");
detectWith in interface RichIterable<K>detectWith in class AbstractRichIterable<V>public java.util.Optional<V> detectOptional(Predicate<? super V> predicate)
RichIterableExample using a Java 8 lambda expression:
Person person =
people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
detectOptional in interface RichIterable<K>detectOptional in class AbstractRichIterable<V>public <P> java.util.Optional<V> detectWithOptional(Predicate2<? super V,? super P> predicate, P parameter)
RichIterableExample using a Java 8 lambda expression:
Optional<Person> person =
people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
detectWithOptional in interface RichIterable<K>detectWithOptional in class AbstractRichIterable<V>public V detectIfNone(Predicate<? super V> predicate, Function0<? extends V> function)
RichIterabledetectIfNone in interface RichIterable<K>public <P> V detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)
RichIterabledetectWithIfNone in interface RichIterable<K>detectWithIfNone in class AbstractRichIterable<V>public V getFirst()
RichIterableThe order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
getFirst in interface RichIterable<K>public V getLast()
RichIterableThe order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.
getLast in interface RichIterable<K>public V getOnly()
RichIterableIllegalStateException.getOnly in interface RichIterable<K>public java.lang.Object[] toArray()
RichIterabletoArray in interface RichIterable<K>toArray in class AbstractRichIterable<V>Collection.toArray()public <T> T[] toArray(T[] a)
RichIterabletoArray in interface RichIterable<K>toArray in class AbstractRichIterable<V>Collection.toArray(Object[])Copyright © 2004–2020. All rights reserved.