Class LazyIterableAdapter<T>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<T>
-
- org.eclipse.collections.impl.lazy.AbstractLazyIterable<T>
-
- org.eclipse.collections.impl.lazy.LazyIterableAdapter<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,InternalIterable<T>,LazyIterable<T>,RichIterable<T>
public class LazyIterableAdapter<T> extends AbstractLazyIterable<T>
A LazyIterableAdapter wraps any iterable with the LazyIterable interface.
-
-
Constructor Summary
Constructors Constructor Description LazyIterableAdapter(java.lang.Iterable<T> newAdapted)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallSatisfy(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> booleanallSatisfyWith(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.booleananySatisfy(Predicate<? super T> predicate)Returns true if the predicate evaluates to true for any element of the iterable.<P> booleananySatisfyWith(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.Tdetect(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.java.util.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> TdetectWith(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> java.util.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)voideach(Procedure<? super T> procedure)The procedure is executed for each element in the iterable.<V> LazyIterable<V>flatCollect(Function<? super T,? extends java.lang.Iterable<V>> function)Creates a deferred flattening iterable for the current iterable.<P> voidforEachWith(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.voidforEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.TgetFirst()Returns the first element of an iterable.TgetLast()Returns the last element of an iterable.<R extends java.util.Collection<T>>
Rinto(R target)Adds all the elements in this iterable to the specific target Collection.booleanisEmpty()Returns true if this iterable has zero items.java.util.Iterator<T>iterator()booleannoneSatisfy(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> booleannoneSatisfyWith(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.intsize()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)-
Methods inherited from class org.eclipse.collections.impl.lazy.AbstractLazyIterable
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, toStack, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, collect, collectIf, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach
-
Methods inherited from interface org.eclipse.collections.api.LazyIterable
flatCollectWith, toArray, toArray, toImmutableBag, toImmutableList, toImmutableSet
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, aggregateBy, aggregateInPlaceBy, appendString, appendString, appendString, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, 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, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, makeString, makeString, makeString, makeString, max, max, maxBy, min, min, minBy, notEmpty, reduce, reduceBy, reduceBy, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toImmutableBiMap, toImmutableMap, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString, zip, zipWithIndex
-
-
-
-
Field Detail
-
adapted
private final java.lang.Iterable<T> adapted
-
-
Constructor Detail
-
LazyIterableAdapter
public LazyIterableAdapter(java.lang.Iterable<T> newAdapted)
-
-
Method Detail
-
each
public void each(Procedure<? super T> procedure)
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()));
This method is a variant ofInternalIterable.forEach(Procedure)that has a signature conflict withIterable.forEach(java.util.function.Consumer).- See Also:
InternalIterable.forEach(Procedure),Iterable.forEach(java.util.function.Consumer)
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
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<T>- Overrides:
forEachWithIndexin classAbstractRichIterable<T>
-
forEachWith
public <P> void forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
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<T>- Overrides:
forEachWithin classAbstractRichIterable<T>
-
iterator
public java.util.Iterator<T> iterator()
-
into
public <R extends java.util.Collection<T>> R into(R target)
Description copied from interface:RichIterableAdds all the elements in this iterable to the specific target Collection.- Specified by:
intoin interfaceLazyIterable<T>- Specified by:
intoin interfaceRichIterable<T>- Overrides:
intoin classAbstractLazyIterable<T>
-
select
public LazyIterable<T> select(Predicate<? super T> predicate)
Description copied from interface:LazyIterableCreates a deferred iterable for selecting elements from the current iterable.- Specified by:
selectin interfaceLazyIterable<T>- Specified by:
selectin interfaceRichIterable<T>- Overrides:
selectin classAbstractLazyIterable<T>
-
reject
public LazyIterable<T> reject(Predicate<? super T> predicate)
Description copied from interface:LazyIterableCreates a deferred iterable for rejecting elements from the current iterable.- Specified by:
rejectin interfaceLazyIterable<T>- Specified by:
rejectin interfaceRichIterable<T>- Overrides:
rejectin classAbstractLazyIterable<T>- Parameters:
predicate- aPredicateto use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)method to evaluate to false
-
collect
public <V> LazyIterable<V> collect(Function<? super T,? extends V> function)
Description copied from interface:LazyIterableCreates a deferred iterable for collecting elements from the current iterable.- Specified by:
collectin interfaceLazyIterable<T>- Specified by:
collectin interfaceRichIterable<T>- Overrides:
collectin classAbstractLazyIterable<T>
-
flatCollect
public <V> LazyIterable<V> flatCollect(Function<? super T,? extends java.lang.Iterable<V>> function)
Description copied from interface:LazyIterableCreates a deferred flattening iterable for the current iterable.- Specified by:
flatCollectin interfaceLazyIterable<T>- Specified by:
flatCollectin interfaceRichIterable<T>- Overrides:
flatCollectin classAbstractLazyIterable<T>- Parameters:
function- TheFunctionto 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:LazyIterableCreates a deferred iterable for selecting and collecting elements from the current iterable.- Specified by:
collectIfin interfaceLazyIterable<T>- Specified by:
collectIfin interfaceRichIterable<T>- Overrides:
collectIfin classAbstractLazyIterable<T>
-
take
public LazyIterable<T> take(int count)
Description copied from interface:LazyIterableCreates a deferred take iterable for the current iterable using the specified count as the limit.- Specified by:
takein interfaceLazyIterable<T>- Overrides:
takein classAbstractLazyIterable<T>
-
drop
public LazyIterable<T> drop(int count)
Description copied from interface:LazyIterableCreates a deferred drop iterable for the current iterable using the specified count as the limit.- Specified by:
dropin interfaceLazyIterable<T>- Overrides:
dropin classAbstractLazyIterable<T>
-
takeWhile
public LazyIterable<T> takeWhile(Predicate<? super T> predicate)
- Specified by:
takeWhilein interfaceLazyIterable<T>- Overrides:
takeWhilein classAbstractLazyIterable<T>- See Also:
OrderedIterable.takeWhile(Predicate)
-
dropWhile
public LazyIterable<T> dropWhile(Predicate<? super T> predicate)
- Specified by:
dropWhilein interfaceLazyIterable<T>- Overrides:
dropWhilein classAbstractLazyIterable<T>- See Also:
OrderedIterable.dropWhile(Predicate)
-
distinct
public LazyIterable<T> distinct()
Description copied from interface:LazyIterableCreates a deferred distinct iterable to get distinct elements from the current iterable.- Specified by:
distinctin interfaceLazyIterable<T>- Overrides:
distinctin classAbstractLazyIterable<T>
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfaceRichIterable<T>- Overrides:
sizein classAbstractLazyIterable<T>
-
isEmpty
public boolean isEmpty()
Description copied from interface:RichIterableReturns true if this iterable has zero items.- Specified by:
isEmptyin interfaceRichIterable<T>- Overrides:
isEmptyin classAbstractLazyIterable<T>
-
anySatisfy
public boolean anySatisfy(Predicate<? super T> predicate)
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<T>- Overrides:
anySatisfyin classAbstractRichIterable<T>
-
allSatisfy
public boolean allSatisfy(Predicate<? super T> predicate)
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<T>- Overrides:
allSatisfyin classAbstractRichIterable<T>
-
noneSatisfy
public boolean noneSatisfy(Predicate<? super T> predicate)
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<T>- Overrides:
noneSatisfyin classAbstractRichIterable<T>
-
anySatisfyWith
public <P> boolean anySatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
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<T>- Overrides:
anySatisfyWithin classAbstractRichIterable<T>
-
allSatisfyWith
public <P> boolean allSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
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<T>- Overrides:
allSatisfyWithin classAbstractRichIterable<T>
-
noneSatisfyWith
public <P> boolean noneSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
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<T>- Overrides:
noneSatisfyWithin classAbstractRichIterable<T>
-
getFirst
public T 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 interfaceLazyIterable<T>- Specified by:
getFirstin interfaceRichIterable<T>- Overrides:
getFirstin classAbstractLazyIterable<T>
-
getLast
public T 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<T>- Overrides:
getLastin classAbstractLazyIterable<T>
-
detect
public T detect(Predicate<? super T> predicate)
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"));- Specified by:
detectin interfaceRichIterable<T>- Overrides:
detectin classAbstractRichIterable<T>
-
detectWith
public <P> T detectWith(Predicate2<? super T,? super P> predicate, P parameter)
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");- Specified by:
detectWithin interfaceRichIterable<T>- Overrides:
detectWithin classAbstractRichIterable<T>
-
detectOptional
public java.util.Optional<T> detectOptional(Predicate<? super T> predicate)
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<T>- Overrides:
detectOptionalin classAbstractRichIterable<T>
-
detectWithOptional
public <P> java.util.Optional<T> detectWithOptional(Predicate2<? super T,? super P> predicate, P parameter)
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<T>- Overrides:
detectWithOptionalin classAbstractRichIterable<T>
-
-