Class AbstractMapIterable<K,V>
- All Implemented Interfaces:
Iterable<V>
,InternalIterable<V>
,MapIterable<K,V>
,RichIterable<V>
- Direct Known Subclasses:
AbstractImmutableMap
,AbstractImmutableSortedMap
,AbstractMutableMapIterable
,OrderedMapAdapter
public abstract class AbstractMapIterable<K,V> extends AbstractRichIterable<V> implements MapIterable<K,V>
-
Constructor Summary
Constructors Constructor Description AbstractMapIterable()
-
Method Summary
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(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.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> 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 theprocedure
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, returnvalue
.<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.V
getOrDefault(Object key, V defaultValue)
<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.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.Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
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, zipWithIndex
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.collections.api.map.MapIterable
aggregateBy, collect, collectValues, containsKey, containsValue, detect, detectOptional, equals, flip, flipUniqueValues, forEachKeyValue, get, hashCode, keysView, keyValuesView, parallelStream, reject, select, spliterator, stream, tap, toImmutable, toString, valuesView
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, aggregateBy, 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, containsBy, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, flatCollect, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, 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, zipWithIndex
-
Constructor Details
-
AbstractMapIterable
public AbstractMapIterable()
-
-
Method Details
-
ifPresentApply
Description copied from interface:MapIterable
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.- Specified by:
ifPresentApply
in interfaceMapIterable<K,V>
-
getOrDefault
- Specified by:
getOrDefault
in interfaceMapIterable<K,V>
-
getIfAbsent
Description copied from interface:MapIterable
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.- Specified by:
getIfAbsent
in interfaceMapIterable<K,V>
-
getIfAbsentValue
Description copied from interface:MapIterable
Return the value in the Map that corresponds to the specified key, or if there is no value at the key, returnvalue
.- Specified by:
getIfAbsentValue
in interfaceMapIterable<K,V>
-
getIfAbsentWith
Description copied from interface:MapIterable
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.- Specified by:
getIfAbsentWith
in interfaceMapIterable<K,V>
-
anySatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.- Specified by:
anySatisfy
in interfaceRichIterable<K>
- Overrides:
anySatisfy
in classAbstractRichIterable<V>
-
anySatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.- Specified by:
anySatisfyWith
in interfaceRichIterable<K>
- Overrides:
anySatisfyWith
in classAbstractRichIterable<V>
-
allSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfy
in interfaceRichIterable<K>
- Overrides:
allSatisfy
in classAbstractRichIterable<V>
-
allSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWith
in interfaceRichIterable<K>
- Overrides:
allSatisfyWith
in classAbstractRichIterable<V>
-
noneSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfy
in interfaceRichIterable<K>
- Overrides:
noneSatisfy
in classAbstractRichIterable<V>
-
noneSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.- Specified by:
noneSatisfyWith
in interfaceRichIterable<K>
- Overrides:
noneSatisfyWith
in classAbstractRichIterable<V>
-
asLazy
Description copied from interface:RichIterable
Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).- Specified by:
asLazy
in interfaceRichIterable<K>
- Overrides:
asLazy
in classAbstractRichIterable<V>
-
chunk
Description copied from interface:RichIterable
Partitions elements in fixed size chunks.- Specified by:
chunk
in interfaceRichIterable<K>
- Parameters:
size
- the number of elements per chunk- Returns:
- A
RichIterable
containingRichIterable
s of sizesize
, except the last will be truncated if the elements don't divide evenly.
-
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)
.- Specified by:
each
in interfaceRichIterable<K>
- See Also:
InternalIterable.forEach(Procedure)
,Iterable.forEach(java.util.function.Consumer)
-
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<K>
- Overrides:
forEachWith
in classAbstractRichIterable<V>
-
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<K>
- Overrides:
forEachWithIndex
in classAbstractRichIterable<V>
-
forEachKey
Description copied from interface:MapIterable
Calls theprocedure
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);
- Specified by:
forEachKey
in interfaceMapIterable<K,V>
-
forEachValue
Description copied from interface:MapIterable
Calls the procedure with each value of the map.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);
- Specified by:
forEachValue
in interfaceMapIterable<K,V>
-
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 interfaceRichIterable<K>
- Overrides:
contains
in classAbstractRichIterable<V>
-
detect
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.Example 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"); } });
- Specified by:
detect
in interfaceRichIterable<K>
- Overrides:
detect
in classAbstractRichIterable<V>
-
detectWith
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.Example 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");
- Specified by:
detectWith
in interfaceRichIterable<K>
- Overrides:
detectWith
in classAbstractRichIterable<V>
-
detectOptional
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
- Specified by:
detectOptional
in interfaceRichIterable<K>
- Overrides:
detectOptional
in classAbstractRichIterable<V>
-
detectWithOptional
Description copied from interface:RichIterable
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
- Specified by:
detectWithOptional
in interfaceRichIterable<K>
- Overrides:
detectWithOptional
in classAbstractRichIterable<V>
-
detectIfNone
Description copied from interface:RichIterable
Returns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.- Specified by:
detectIfNone
in interfaceRichIterable<K>
-
detectWithIfNone
public <P> V detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)Description copied from interface:RichIterable
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.- Specified by:
detectWithIfNone
in interfaceRichIterable<K>
- Overrides:
detectWithIfNone
in classAbstractRichIterable<V>
-
getFirst
Description copied from interface:RichIterable
Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The 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.
- Specified by:
getFirst
in interfaceRichIterable<K>
-
getLast
Description copied from interface:RichIterable
Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The 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.
- Specified by:
getLast
in interfaceRichIterable<K>
-
getOnly
Description copied from interface:RichIterable
Returns the element if the iterable has exactly one element. Otherwise, throwIllegalStateException
.- Specified by:
getOnly
in interfaceRichIterable<K>
- Returns:
- an element of an iterable.
-
toArray
Description copied from interface:RichIterable
Converts this iterable to an array.- Specified by:
toArray
in interfaceRichIterable<K>
- Overrides:
toArray
in classAbstractRichIterable<V>
- See Also:
Collection.toArray()
-
toArray
public <T> T[] toArray(T[] a)Description copied from interface:RichIterable
Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArray
in interfaceRichIterable<K>
- Overrides:
toArray
in classAbstractRichIterable<V>
- See Also:
Collection.toArray(Object[])
-