Class LazyIterableAdapter<T>
- All Implemented Interfaces:
Iterable<T>
,InternalIterable<T>
,LazyIterable<T>
,RichIterable<T>
public class LazyIterableAdapter<T> extends AbstractLazyIterable<T>
-
Constructor Summary
Constructors Constructor Description LazyIterableAdapter(Iterable<T> newAdapted)
-
Method Summary
Modifier and Type Method Description boolean
allSatisfy(Predicate<? super T> 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 T,? 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 T> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.<P> boolean
anySatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
Returns true if the predicate evaluates to true for any element of the collection, or return false.<V> LazyIterable<V>
collect(Function<? super T,? extends V> function)
Creates a deferred iterable for collecting elements from the current iterable.<V> LazyIterable<V>
collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)
Creates a deferred iterable for selecting and collecting elements from the current iterable.T
detect(Predicate<? super T> 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.Optional<T>
detectOptional(Predicate<? super T> predicate)
Returns the first element of the iterable for which the predicate evaluates to true as an Optional.<P> T
detectWith(Predicate2<? super T,? 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> Optional<T>
detectWithOptional(Predicate2<? super T,? super P> predicate, P parameter)
Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.LazyIterable<T>
distinct()
Creates a deferred distinct iterable to get distinct elements from the current iterable.LazyIterable<T>
drop(int count)
Creates a deferred drop iterable for the current iterable using the specified count as the limit.LazyIterable<T>
dropWhile(Predicate<? super T> predicate)
void
each(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.<V> LazyIterable<V>
flatCollect(Function<? super T,? extends Iterable<V>> function)
Creates a deferred flattening iterable for the current iterable.<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.T
getFirst()
Returns the first element of an iterable.T
getLast()
Returns the last element of an iterable.<R extends Collection<T>>
Rinto(R target)
Adds all the elements in this iterable to the specific target Collection.boolean
isEmpty()
Returns true if this iterable has zero items.Iterator<T>
iterator()
boolean
noneSatisfy(Predicate<? super T> 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 T,? super P> predicate, P parameter)
Returns true if the predicate evaluates to false for every element of the collection, or return false.LazyIterable<T>
reject(Predicate<? super T> predicate)
Creates a deferred iterable for rejecting elements from the current iterable.LazyIterable<T>
select(Predicate<? super T> predicate)
Creates a deferred iterable for selecting elements from the current iterable.int
size()
Returns the number of items in this iterable.LazyIterable<T>
take(int count)
Creates a deferred take iterable for the current iterable using the specified count as the limit.LazyIterable<T>
takeWhile(Predicate<? super T> predicate)
Object[]
toArray()
Converts this iterable to an array.Methods inherited from class org.eclipse.collections.impl.lazy.AbstractLazyIterable
aggregateInPlaceBy, asLazy, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, collectWith, concatenate, getOnly, groupBy, groupByEach, groupByUniqueKey, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, partition, partitionWith, rejectWith, selectInstancesOf, selectWith, sumByDouble, sumByFloat, sumByInt, sumByLong, tap, toArray, toStack, zip, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countByEach, countWith, detectWithIfNone, flatCollect, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, 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.RichIterable
aggregateBy, aggregateBy, appendString, appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsBy, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detectIfNone, detectWithIfNone, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, 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, toString, zip, zipWithIndex
-
Constructor Details
-
Method Details
-
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)
. -
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<T>
- Overrides:
forEachWithIndex
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
forEachWith
in classAbstractRichIterable<T>
-
iterator
-
into
Description copied from interface:RichIterable
Adds all the elements in this iterable to the specific target Collection.- Specified by:
into
in interfaceLazyIterable<T>
- Specified by:
into
in interfaceRichIterable<T>
- Overrides:
into
in classAbstractLazyIterable<T>
-
select
Description copied from interface:LazyIterable
Creates a deferred iterable for selecting elements from the current iterable.- Specified by:
select
in interfaceLazyIterable<T>
- Specified by:
select
in interfaceRichIterable<T>
- Overrides:
select
in classAbstractLazyIterable<T>
-
reject
Description copied from interface:LazyIterable
Creates a deferred iterable for rejecting elements from the current iterable.- Specified by:
reject
in interfaceLazyIterable<T>
- Specified by:
reject
in interfaceRichIterable<T>
- Overrides:
reject
in classAbstractLazyIterable<T>
- Parameters:
predicate
- aPredicate
to use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)
method to evaluate to false
-
collect
Description copied from interface:LazyIterable
Creates a deferred iterable for collecting elements from the current iterable.- Specified by:
collect
in interfaceLazyIterable<T>
- Specified by:
collect
in interfaceRichIterable<T>
- Overrides:
collect
in classAbstractLazyIterable<T>
-
flatCollect
Description copied from interface:LazyIterable
Creates a deferred flattening iterable for the current iterable.- Specified by:
flatCollect
in interfaceLazyIterable<T>
- Specified by:
flatCollect
in interfaceRichIterable<T>
- Overrides:
flatCollect
in classAbstractLazyIterable<T>
- Parameters:
function
- TheFunction
to apply- Returns:
- a new flattened collection produced by applying the given
function
-
collectIf
public <V> LazyIterable<V> collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function)Description copied from interface:LazyIterable
Creates a deferred iterable for selecting and collecting elements from the current iterable.- Specified by:
collectIf
in interfaceLazyIterable<T>
- Specified by:
collectIf
in interfaceRichIterable<T>
- Overrides:
collectIf
in classAbstractLazyIterable<T>
-
take
Description copied from interface:LazyIterable
Creates a deferred take iterable for the current iterable using the specified count as the limit.- Specified by:
take
in interfaceLazyIterable<T>
- Overrides:
take
in classAbstractLazyIterable<T>
-
drop
Description copied from interface:LazyIterable
Creates a deferred drop iterable for the current iterable using the specified count as the limit.- Specified by:
drop
in interfaceLazyIterable<T>
- Overrides:
drop
in classAbstractLazyIterable<T>
-
takeWhile
- Specified by:
takeWhile
in interfaceLazyIterable<T>
- Overrides:
takeWhile
in classAbstractLazyIterable<T>
- See Also:
OrderedIterable.takeWhile(Predicate)
-
dropWhile
- Specified by:
dropWhile
in interfaceLazyIterable<T>
- Overrides:
dropWhile
in classAbstractLazyIterable<T>
- See Also:
OrderedIterable.dropWhile(Predicate)
-
distinct
Description copied from interface:LazyIterable
Creates a deferred distinct iterable to get distinct elements from the current iterable.- Specified by:
distinct
in interfaceLazyIterable<T>
- Overrides:
distinct
in classAbstractLazyIterable<T>
-
toArray
Description copied from interface:RichIterable
Converts this iterable to an array.- Specified by:
toArray
in interfaceRichIterable<T>
- Overrides:
toArray
in classAbstractRichIterable<T>
- See Also:
Collection.toArray()
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable.- Specified by:
size
in interfaceRichIterable<T>
- Overrides:
size
in classAbstractLazyIterable<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceRichIterable<T>
- Overrides:
isEmpty
in classAbstractLazyIterable<T>
-
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<T>
- Overrides:
anySatisfy
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
allSatisfy
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
noneSatisfy
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
anySatisfyWith
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
allSatisfyWith
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
noneSatisfyWith
in classAbstractRichIterable<T>
-
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 interfaceLazyIterable<T>
- Specified by:
getFirst
in interfaceRichIterable<T>
- Overrides:
getFirst
in classAbstractLazyIterable<T>
-
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<T>
- Overrides:
getLast
in classAbstractLazyIterable<T>
-
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<T>
- Overrides:
detect
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
detectWith
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
detectOptional
in classAbstractRichIterable<T>
-
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<T>
- Overrides:
detectWithOptional
in classAbstractRichIterable<T>
-