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 booleanallSatisfy(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> booleanallSatisfyWith(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.booleananySatisfy(Predicate<? super V> predicate)Returns true if the predicate evaluates to true for any element of the iterable.<P> booleananySatisfyWith(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.booleancontains(Object object)Returns true if the iterable has an element which responds true to element.equals(object).Vdetect(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.VdetectIfNone(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> VdetectWith(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> VdetectWithIfNone(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.voideach(Procedure<? super V> procedure)The procedure is executed for each element in the iterable.voidforEachKey(Procedure<? super K> procedure)Calls theprocedurewith each key of the map.voidforEachValue(Procedure<? super V> procedure)Calls the procedure with each value of the map.<P> voidforEachWith(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.voidforEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.VgetFirst()Returns the first element of an iterable.VgetIfAbsent(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.VgetIfAbsentValue(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> VgetIfAbsentWith(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.VgetLast()Returns the last element of an iterable.VgetOnly()Returns the element if the iterable has exactly one element.VgetOrDefault(Object key, V defaultValue)<A> AifPresentApply(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.booleannoneSatisfy(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> booleannoneSatisfyWith(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, zipWithIndexMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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, valuesViewMethods 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:MapIterableIf 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:
ifPresentApplyin interfaceMapIterable<K,V>
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMapIterable<K,V>
-
getIfAbsent
Description copied from interface:MapIterableReturn 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:
getIfAbsentin interfaceMapIterable<K,V>
-
getIfAbsentValue
Description copied from interface:MapIterableReturn the value in the Map that corresponds to the specified key, or if there is no value at the key, returnvalue.- Specified by:
getIfAbsentValuein interfaceMapIterable<K,V>
-
getIfAbsentWith
Description copied from interface:MapIterableReturn 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:
getIfAbsentWithin interfaceMapIterable<K,V>
-
anySatisfy
Description copied from interface:RichIterableReturns 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:
anySatisfyin interfaceRichIterable<K>- Overrides:
anySatisfyin classAbstractRichIterable<V>
-
anySatisfyWith
Description copied from interface:RichIterableReturns 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:
anySatisfyWithin interfaceRichIterable<K>- Overrides:
anySatisfyWithin classAbstractRichIterable<V>
-
allSatisfy
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfyin interfaceRichIterable<K>- Overrides:
allSatisfyin classAbstractRichIterable<V>
-
allSatisfyWith
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWithin interfaceRichIterable<K>- Overrides:
allSatisfyWithin classAbstractRichIterable<V>
-
noneSatisfy
Description copied from interface:RichIterableReturns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfyin interfaceRichIterable<K>- Overrides:
noneSatisfyin classAbstractRichIterable<V>
-
noneSatisfyWith
Description copied from interface:RichIterableReturns 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:
noneSatisfyWithin interfaceRichIterable<K>- Overrides:
noneSatisfyWithin classAbstractRichIterable<V>
-
asLazy
Description copied from interface:RichIterableReturns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).- Specified by:
asLazyin interfaceRichIterable<K>- Overrides:
asLazyin classAbstractRichIterable<V>
-
chunk
Description copied from interface:RichIterablePartitions elements in fixed size chunks.- Specified by:
chunkin interfaceRichIterable<K>- Parameters:
size- the number of elements per chunk- Returns:
- A
RichIterablecontainingRichIterables of sizesize, except the last will be truncated if the elements don't divide evenly.
-
each
Description copied from interface:RichIterableThe 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:
eachin interfaceRichIterable<K>- See Also:
InternalIterable.forEach(Procedure),Iterable.forEach(java.util.function.Consumer)
-
forEachWith
Description copied from interface:InternalIterableThe 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:
forEachWithin interfaceInternalIterable<K>- Overrides:
forEachWithin classAbstractRichIterable<V>
-
forEachWithIndex
Description copied from interface:InternalIterableIterates 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:
forEachWithIndexin interfaceInternalIterable<K>- Overrides:
forEachWithIndexin classAbstractRichIterable<V>
-
forEachKey
Description copied from interface:MapIterableCalls theprocedurewith 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:
forEachKeyin interfaceMapIterable<K,V>
-
forEachValue
Description copied from interface:MapIterableCalls 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:
forEachValuein interfaceMapIterable<K,V>
-
contains
Description copied from interface:RichIterableReturns true if the iterable has an element which responds true to element.equals(object).- Specified by:
containsin interfaceRichIterable<K>- Overrides:
containsin classAbstractRichIterable<V>
-
detect
Description copied from interface:RichIterableReturns 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:
detectin interfaceRichIterable<K>- Overrides:
detectin classAbstractRichIterable<V>
-
detectWith
Description copied from interface:RichIterableReturns 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:
detectWithin interfaceRichIterable<K>- Overrides:
detectWithin classAbstractRichIterable<V>
-
detectOptional
Description copied from interface:RichIterableReturns 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:
detectOptionalin interfaceRichIterable<K>- Overrides:
detectOptionalin classAbstractRichIterable<V>
-
detectWithOptional
Description copied from interface:RichIterableReturns 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:
detectWithOptionalin interfaceRichIterable<K>- Overrides:
detectWithOptionalin classAbstractRichIterable<V>
-
detectIfNone
Description copied from interface:RichIterableReturns 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:
detectIfNonein interfaceRichIterable<K>
-
detectWithIfNone
public <P> V detectWithIfNone(Predicate2<? super V,? super P> predicate, P parameter, Function0<? extends V> function)Description copied from interface:RichIterableReturns 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:
detectWithIfNonein interfaceRichIterable<K>- Overrides:
detectWithIfNonein classAbstractRichIterable<V>
-
getFirst
Description copied from interface:RichIterableReturns 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:
getFirstin interfaceRichIterable<K>
-
getLast
Description copied from interface:RichIterableReturns 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:
getLastin interfaceRichIterable<K>
-
getOnly
Description copied from interface:RichIterableReturns the element if the iterable has exactly one element. Otherwise, throwIllegalStateException.- Specified by:
getOnlyin interfaceRichIterable<K>- Returns:
- an element of an iterable.
-
toArray
Description copied from interface:RichIterableConverts this iterable to an array.- Specified by:
toArrayin interfaceRichIterable<K>- Overrides:
toArrayin classAbstractRichIterable<V>- See Also:
Collection.toArray()
-
toArray
public <T> T[] toArray(T[] a)Description copied from interface:RichIterableConverts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArrayin interfaceRichIterable<K>- Overrides:
toArrayin classAbstractRichIterable<V>- See Also:
Collection.toArray(Object[])
-