Package org.apache.jena.atlas.iterator
Class Iter<T>
- java.lang.Object
-
- org.apache.jena.atlas.iterator.Iter<T>
-
- Type Parameters:
T- the type of element over which an instance ofIteriterates,
- All Implemented Interfaces:
java.util.Iterator<T>,IteratorCloseable<T>,Closeable
public class Iter<T> extends java.lang.Object implements IteratorCloseable<T>
Iter provides general utilities for working with Iterators. This class provides functionality similar toStreamexcept for iterators (and hence single threaded).Style 1: functional style using statics.
import static org.apache.jena.atlas.iterator.Iter.*; filter(map(iterator, function), predicate)
Style 2: Stream-like: The classIterprovides methods to call on an iterator.import static org.apache.jena.atlas.iterator.Iter.iter; iter(iterator).map(...).filter(...)
The operations attempt to close iterators - seeclose(Iterator). Caution - not all Iterators in this package provide close or passdown close operationsIteratorOnCloseadds aRunnableaction called once on close.Iterators do not guarantee
.remove.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIter.Folder<X,Y>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallMatch(java.util.function.Predicate<? super T> predicate)static <T> booleanallMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if every element of stream passes the filter (reads the stream until the first element not passing the filter)booleananyMatch(java.util.function.Predicate<? super T> predicate)static <T> booleananyMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if one or more elements of stream passes the filter (reads the stream to first element passing the filter)static <T> java.util.Iterator<T>append(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2)Join two iterators.Iter<T>append(java.util.Iterator<T> iter)Join on anIterator..voidapply(java.util.function.Consumer<T> action)Apply an action to every element of an iteratorstatic <T> voidapply(java.util.Iterator<? extends T> stream, java.util.function.Consumer<T> action)Act on elements of an iterator.static <T> java.util.stream.Stream<T>asStream(java.util.Iterator<T> iterator)static <T> java.util.stream.Stream<T>asStream(java.util.Iterator<T> iterator, boolean parallel)static <T> java.lang.StringasString(java.util.Iterator<T> stream, java.lang.CharSequence sep, java.lang.CharSequence prefix, java.lang.CharSequence suffix)Create a string from an iterator, using the separator, prefix and suffix.static <T> java.lang.StringasString(java.util.Iterator<T> stream, java.lang.String sep)Create a string from an iterator, using the separator.voidclose()static <T> voidclose(java.util.Iterator<T> iter)Close iterator if marked withCloseable.<R> Rcollect(java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,T> accumulator)SeeStream.collect(Supplier, BiConsumer, BiConsumer), except without theBiConsumer<R, R> combinerstatic <T,R>
Rcollect(java.util.Iterator<T> iter, java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,? super T> accumulator)SeeStream.collect(Supplier, BiConsumer, BiConsumer), except without theBiConsumer<R, R> combinerstatic <T,R,A>
Rcollect(java.util.Iterator<T> iter, java.util.stream.Collector<? super T,A,R> collector)SeeStream.collect(Collector)<R,A>
Rcollect(java.util.stream.Collector<? super T,A,R> collector)SeeStream.collect(Collector)static <T> Iter<T>concat(java.util.Iterator<T> iter1, java.util.Iterator<T> iter2)AnIteratorof 2Iterator's.static <T> Iter<T>concat(Iter<T> iter1, Iter<T> iter2)AnIterof 2Iter'sstatic <T> voidconsume(java.util.Iterator<T> iterator)Consume the iteratorlongcount()Count the iterator (this is destructive on the iterator)static <T> longcount(java.util.Iterator<T> iterator)Count the iterator (this is destructive on the iterator)static <T> java.util.Iterator<T>debug(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator, return a copy of the iterator.static <T> java.util.Iterator<T>debug(java.util.Iterator<T> stream)Print an iterator to stdout, return a copy of the iterator.Iter<T>distinct()Return anIterthat will see each element of the underlying iterator only once.static <T> java.util.Iterator<T>distinct(java.util.Iterator<T> iter)Return an iterator that will see each element of the underlying iterator only once.Iter<T>distinctAdjacent()Remove adjacent duplicates.static <T> java.util.Iterator<T>distinctAdjacent(java.util.Iterator<T> iter)Remove adjacent duplicates.Iter<T>dropUntil(java.util.function.Predicate<T> predicate)Create anItersuch that elements from the front until a predicate test become true are dropped then return all remaining elements are iterated over.static <T> java.util.Iterator<T>dropUntil(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that elements from the front until a predicate test become true are dropped then return all remaining elements are iterated over.Iter<T>dropWhile(java.util.function.Predicate<T> predicate)Create anItersuch that elements from the front while a predicate test become true are dropped then return all remaining elements are iterated over.static <T> java.util.Iterator<T>dropWhile(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that elements from the front while a predicate test become true are dropped then return all remaining elements are iterated over.static <T> Iter<T>empty()Iter<T>filter(java.util.function.Predicate<T> filter)Filter by predicatestatic <T> java.util.Iterator<T>filter(java.util.Iterator<? extends T> stream, java.util.function.Predicate<T> filter)java.util.Optional<T>findAny(java.util.function.Predicate<? super T> predicate)static <T> java.util.Optional<T>findAny(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with an element of an iterator that matches the predicate.java.util.Optional<T>findFirst(java.util.function.Predicate<? super T> predicate)static <T> java.util.Optional<T>findFirst(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with the first element of an iterator that matches the predicate.java.util.Optional<T>findLast(java.util.function.Predicate<? super T> predicate)static <T> java.util.Optional<T>findLast(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with the last element of an iterator that matches the predicate.Tfirst()Tfirst(java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element.static <T> Tfirst(java.util.Iterator<T> iter)Return the first element of an iterator or null if no such element.static <T> Tfirst(java.util.Iterator<T> iter, java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element.intfirstIndex(java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element's index (zero-based).static <T> intfirstIndex(java.util.Iterator<T> iter, java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element's index (zero-based).<R> Iter<R>flatMap(java.util.function.Function<T,java.util.Iterator<R>> converter)FlatMap each element using given function of element to iterator of mapped elements.sstatic <T,R>
java.util.Iterator<R>flatMap(java.util.Iterator<T> iter, java.util.function.Function<T,java.util.Iterator<R>> mapper)Apply a function to every element of an iterator, to produce possibly multiple mapping each time.static <T,R>
RfoldLeft(java.util.Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)<R> RfoldLeft(R initial, Iter.Folder<T,R> accumulator)static <T,R>
RfoldRight(java.util.Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)<R> RfoldRight(R initial, Iter.Folder<T,R> accumulator)voidforEach(java.util.function.Consumer<T> action)Apply the Consumer to each element of the iteratorstatic <T> voidforEach(java.util.Iterator<T> iter, java.util.function.Consumer<T> action)Shorter form of "forEachRemaining"booleanhasNext()static <T> Iter<T>iter(java.util.Collection<T> collection)static <T> Iter<T>iter(java.util.Iterator<T> iterator)static <T> Iter<T>iter(Iter<T> iter)static <T> java.util.Iterator<T>iterator(java.util.Iterator<? extends T> iterator)Create another iterator without risk of concurrent modification exceptions.Tlast()static <T> Tlast(java.util.Iterator<T> iter)Return the last element or null, if no elements.static <T> Tlast(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> filter)Return the last element satisfying a predicate.static <T> intlastIndex(java.util.List<T> list, java.util.function.Predicate<? super T> filter)Find the last occurrence, defined by a predicate, in a list.Iter<T>limit(long N)Limit the number of elements.static <X> java.util.Iterator<X>limit(java.util.Iterator<X> iterator, long limit)Return an iterator that is limited to the given number of elements.static <T> java.util.Iterator<T>log(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator to stdout, return a copy of the iterator.static <T> java.util.Iterator<T>log(java.util.Iterator<T> stream)Print an iterator to stdout, return a copy of the iterator.<R> Iter<R>map(java.util.function.Function<T,R> converter)Map each element using given functionstatic <T,R>
java.util.Iterator<R>map(java.util.Iterator<? extends T> stream, java.util.function.Function<T,R> converter)Apply a function to every element of an iterator, transforming it from aTto anR.static <T> java.util.Iterator<T>materialize(java.util.Iterator<T> iter)Materialize an iterator, that is, force it to run now - useful in debugging or when iteration may modify underlying datastructures.java.util.Optional<T>max(java.util.Comparator<T> comparator)static <T> java.util.Optional<T>max(java.util.Iterator<T> iter, java.util.Comparator<T> comparator)java.util.Optional<T>min(java.util.Comparator<T> comparator)static <T> java.util.Optional<T>min(java.util.Iterator<T> iter, java.util.Comparator<T> comparator)Tnext()booleannoneMatch(java.util.function.Predicate<? super T> predicate)static <T> booleannoneMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if none of the elements of the iterator passes the predicate test reads the stream to first element passing the filter)static <T> java.util.Iterator<T>noRemove(java.util.Iterator<T> iter)Return an iterator that does not permit remove.static <T> java.util.Iterator<T>notFilter(java.util.Iterator<? extends T> stream, java.util.function.Predicate<T> filter)static <T> Iter<T>nullIter()static <T> java.util.Iterator<T>nullIterator()static <T> Iter<T>of(T item)static <T> Iter<T>of(T... items)static <T> Iter<T>ofNullable(T t)static <T> IteratorOnClose<T>onClose(java.util.Iterator<T> iter, java.lang.Runnable closeHandler)Run an action when an iterator is closed.static <T> IteratorCloseable<T>onCloseIO(java.util.Iterator<T> iterator, java.io.Closeable ioThing)Run an action when an iterator is closed.Iter<T>operate(java.util.function.Consumer<T> action)Apply an action to everything in the stream, yielding a stream of the original items.static <T> java.util.Iterator<T>operate(java.util.Iterator<? extends T> stream, java.util.function.Consumer<T> action)Apply an action to everything in stream, yielding a stream of the same items.static <T> voidprint(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator (destructive)static <T> voidprint(java.util.Iterator<T> stream)Print an iterator (destructive)static <T> java.util.Iterator<T>printWrapper(java.io.PrintStream out, java.util.Iterator<? extends T> stream)Print an iterator as it gets used - this adds a printing wrapperstatic <T> java.util.Iterator<T>printWrapper(java.util.Iterator<? extends T> stream)Print an iterator as it gets used - this adds a printing wrapperjava.util.Optional<T>reduce(java.util.function.BinaryOperator<T> accumulator)Reduce.static <T> java.util.Optional<T>reduce(java.util.Iterator<T> iter, java.util.function.BinaryOperator<T> accumulator)static <T> Treduce(java.util.Iterator<T> iter, T identity, java.util.function.BinaryOperator<T> accumulator)Treduce(T identity, java.util.function.BinaryOperator<T> accumulator)voidremove()Iter<T>removeNulls()Remove nullsstatic <T> java.util.Iterator<T>removeNulls(java.util.Iterator<T> iter)Remove nulls from an iteratorstatic <T> voidsendToSink(java.util.Iterator<T> iter, Sink<T> sink)Send the elements of the iterator to a sink - consumes the iteratorvoidsendToSink(Sink<T> sink)static <T> java.util.Iterator<T>singleton(T item)static <T> Iter<T>singletonIter(T item)Iter<T>skip(long N)Skip over a number of elements.static <X> java.util.Iterator<X>skip(java.util.Iterator<X> iterator, long limit)Skip over a number of elements of an iteratorstatic intstep(java.util.Iterator<?> iter, int steps)Step forward up tostepsplaces.Iter<T>take(int N)Return an Iter that yields at most the first N itemsstatic <T> java.util.List<T>take(java.util.Iterator<T> iter, int N)Take the first N elements of an iterator - stop early if too fewIter<T>takeUntil(java.util.function.Predicate<T> predicate)Create anItersuch that it yields elements until a predicate test on the elements becomes true, end the iteration.static <T> java.util.Iterator<T>takeUntil(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that it yields elements until a predicate test on the elements becomes true, end the iteration.Iter<T>takeWhile(java.util.function.Predicate<T> predicate)Create anItersuch that it yields elements while a predicate test on the elements is true, end the iteration.static <T> java.util.Iterator<T>takeWhile(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that it yields elements while a predicate test on the elements is true, end the iteration.java.util.List<T>toList()Consume theIterand produce aListstatic <T> java.util.List<T>toList(java.util.Iterator<? extends T> stream)Collect an iterator into a list.java.util.Set<T>toSet()Consume theIterand produce aSetstatic <T> java.util.Set<T>toSet(java.util.Iterator<? extends T> stream)Collect an iterator into a set.
-
-
-
Method Detail
-
forEach
public static <T> void forEach(java.util.Iterator<T> iter, java.util.function.Consumer<T> action)Shorter form of "forEachRemaining"
-
asStream
public static <T> java.util.stream.Stream<T> asStream(java.util.Iterator<T> iterator)
-
asStream
public static <T> java.util.stream.Stream<T> asStream(java.util.Iterator<T> iterator, boolean parallel)
-
singleton
public static <T> java.util.Iterator<T> singleton(T item)
-
nullIterator
public static <T> java.util.Iterator<T> nullIterator()
-
empty
public static <T> Iter<T> empty()
-
of
public static <T> Iter<T> of(T item)
-
of
@SafeVarargs public static <T> Iter<T> of(T... items)
-
ofNullable
public static <T> Iter<T> ofNullable(T t)
-
noRemove
public static <T> java.util.Iterator<T> noRemove(java.util.Iterator<T> iter)
Return an iterator that does not permit remove. This makes an "UnmodifiableIterator".
-
toSet
public static <T> java.util.Set<T> toSet(java.util.Iterator<? extends T> stream)
Collect an iterator into a set.
-
toList
public static <T> java.util.List<T> toList(java.util.Iterator<? extends T> stream)
Collect an iterator into a list.
-
iterator
public static <T> java.util.Iterator<T> iterator(java.util.Iterator<? extends T> iterator)
Create another iterator without risk of concurrent modification exceptions. This materializes the input iterator.
-
foldLeft
public static <T,R> R foldLeft(java.util.Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)
-
foldRight
public static <T,R> R foldRight(java.util.Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)
-
reduce
public static <T> java.util.Optional<T> reduce(java.util.Iterator<T> iter, java.util.function.BinaryOperator<T> accumulator)
-
reduce
public static <T> T reduce(java.util.Iterator<T> iter, T identity, java.util.function.BinaryOperator<T> accumulator)
-
min
public static <T> java.util.Optional<T> min(java.util.Iterator<T> iter, java.util.Comparator<T> comparator)
-
max
public static <T> java.util.Optional<T> max(java.util.Iterator<T> iter, java.util.Comparator<T> comparator)
-
collect
public static <T,R> R collect(java.util.Iterator<T> iter, java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,? super T> accumulator)SeeStream.collect(Supplier, BiConsumer, BiConsumer), except without theBiConsumer<R, R> combiner
-
collect
public static <T,R,A> R collect(java.util.Iterator<T> iter, java.util.stream.Collector<? super T,A,R> collector)SeeStream.collect(Collector)
-
apply
public static <T> void apply(java.util.Iterator<? extends T> stream, java.util.function.Consumer<T> action)Act on elements of an iterator.- See Also:
map(Iterator, Function)
-
filter
public static <T> java.util.Iterator<T> filter(java.util.Iterator<? extends T> stream, java.util.function.Predicate<T> filter)
-
notFilter
public static <T> java.util.Iterator<T> notFilter(java.util.Iterator<? extends T> stream, java.util.function.Predicate<T> filter)
-
allMatch
public static <T> boolean allMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if every element of stream passes the filter (reads the stream until the first element not passing the filter)
-
anyMatch
public static <T> boolean anyMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if one or more elements of stream passes the filter (reads the stream to first element passing the filter)
-
noneMatch
public static <T> boolean noneMatch(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return true if none of the elements of the iterator passes the predicate test reads the stream to first element passing the filter)
-
findFirst
public static <T> java.util.Optional<T> findFirst(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with the first element of an iterator that matches the predicate. ReturnOptional.emptyif none match. Reads the iterator until the first match.
-
findLast
public static <T> java.util.Optional<T> findLast(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with the last element of an iterator that matches the predicate. ReturnOptional.emptyif no match. Reads the iterator to completion.
-
findAny
public static <T> java.util.Optional<T> findAny(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> predicate)Return an Optional with an element of an iterator that matches the predicate. ReturnOptional.emptyif none match. The element returned is not specified by the API contract.
-
map
public static <T,R> java.util.Iterator<R> map(java.util.Iterator<? extends T> stream, java.util.function.Function<T,R> converter)Apply a function to every element of an iterator, transforming it from aTto anR.
-
flatMap
public static <T,R> java.util.Iterator<R> flatMap(java.util.Iterator<T> iter, java.util.function.Function<T,java.util.Iterator<R>> mapper)Apply a function to every element of an iterator, to produce possibly multiple mapping each time. SeeStream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)
-
operate
public static <T> java.util.Iterator<T> operate(java.util.Iterator<? extends T> stream, java.util.function.Consumer<T> action)Apply an action to everything in stream, yielding a stream of the same items.
-
printWrapper
public static <T> java.util.Iterator<T> printWrapper(java.util.Iterator<? extends T> stream)
Print an iterator as it gets used - this adds a printing wrapper
-
printWrapper
public static <T> java.util.Iterator<T> printWrapper(java.io.PrintStream out, java.util.Iterator<? extends T> stream)Print an iterator as it gets used - this adds a printing wrapper
-
append
public static <T> java.util.Iterator<T> append(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2)Join two iterators. If there, potentially, going to be many iterators, it is better to create anIteratorConcatexplicitly and add each iterator.
-
distinct
public static <T> java.util.Iterator<T> distinct(java.util.Iterator<T> iter)
Return an iterator that will see each element of the underlying iterator only once. Note that this need working memory to remember the elements already seen.
-
distinctAdjacent
public static <T> java.util.Iterator<T> distinctAdjacent(java.util.Iterator<T> iter)
Remove adjacent duplicates. This operation does not need working memory to remember the all elements already seen, just a slot for the last element seen.
-
removeNulls
public static <T> java.util.Iterator<T> removeNulls(java.util.Iterator<T> iter)
Remove nulls from an iterator
-
step
public static int step(java.util.Iterator<?> iter, int steps)Step forward up tostepsplaces.
Return number of steps taken.- API Note:
- The iterator is moved at most
stepsplaces with no overshoot. The iterator can be used afterwards.
-
take
public static <T> java.util.List<T> take(java.util.Iterator<T> iter, int N)Take the first N elements of an iterator - stop early if too few- See Also:
limit(Iterator, long)
-
takeWhile
public static <T> java.util.Iterator<T> takeWhile(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that it yields elements while a predicate test on the elements is true, end the iteration.- See Also:
filter(Iterator, Predicate)
-
takeUntil
public static <T> java.util.Iterator<T> takeUntil(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that it yields elements until a predicate test on the elements becomes true, end the iteration.- See Also:
filter(Iterator, Predicate)
-
dropWhile
public static <T> java.util.Iterator<T> dropWhile(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that elements from the front while a predicate test become true are dropped then return all remaining elements are iterated over. The first element where the predicted becomes true is the first element of the returned iterator.
-
dropUntil
public static <T> java.util.Iterator<T> dropUntil(java.util.Iterator<T> iter, java.util.function.Predicate<T> predicate)Create an iterator such that elements from the front until a predicate test become true are dropped then return all remaining elements are iterated over. The first element where the predicate becomes true is the first element of the returned iterator.
-
limit
public static <X> java.util.Iterator<X> limit(java.util.Iterator<X> iterator, long limit)Return an iterator that is limited to the given number of elements. If it is shorter than the limit, stop at the end.- See Also:
take(Iterator, int)
-
skip
public static <X> java.util.Iterator<X> skip(java.util.Iterator<X> iterator, long limit)Skip over a number of elements of an iterator
-
count
public static <T> long count(java.util.Iterator<T> iterator)
Count the iterator (this is destructive on the iterator)
-
consume
public static <T> void consume(java.util.Iterator<T> iterator)
Consume the iterator
-
asString
public static <T> java.lang.String asString(java.util.Iterator<T> stream, java.lang.String sep)Create a string from an iterator, using the separator. Note: this consumes the iterator.
-
asString
public static <T> java.lang.String asString(java.util.Iterator<T> stream, java.lang.CharSequence sep, java.lang.CharSequence prefix, java.lang.CharSequence suffix)Create a string from an iterator, using the separator, prefix and suffix. Note: this consumes the iterator.
-
close
public static <T> void close(java.util.Iterator<T> iter)
Close iterator if marked withCloseable.
-
onCloseIO
public static <T> IteratorCloseable<T> onCloseIO(java.util.Iterator<T> iterator, java.io.Closeable ioThing)
Run an action when an iterator is closed. This assumes the iterator closed withclose(java.util.Iterator<T>).Convenience function for closing a
Closeableafter use when passing an iterator out of scope.
-
onClose
public static <T> IteratorOnClose<T> onClose(java.util.Iterator<T> iter, java.lang.Runnable closeHandler)
Run an action when an iterator is closed. This assumes the iterator closed withclose(java.util.Iterator<T>).
-
log
public static <T> java.util.Iterator<T> log(java.util.Iterator<T> stream)
Print an iterator to stdout, return a copy of the iterator. Printing occurs now. Seedebug(java.util.Iterator<T>)for an operation to print as the iterator is used.
-
log
public static <T> java.util.Iterator<T> log(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator to stdout, return a copy of the iterator. Printing occurs now. Seedebug(java.util.Iterator<T>)for an operation to print as the iterator is used.
-
debug
public static <T> java.util.Iterator<T> debug(java.util.Iterator<T> stream)
Print an iterator to stdout, return a copy of the iterator. Printing occurs when the iterator is used. Seelog(java.util.Iterator<T>)for an operation to print now.
-
debug
public static <T> java.util.Iterator<T> debug(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator, return a copy of the iterator. Printing occurs as the returned iterator is used.
-
print
public static <T> void print(java.util.Iterator<T> stream)
Print an iterator (destructive)
-
print
public static <T> void print(java.io.PrintStream out, java.util.Iterator<T> stream)Print an iterator (destructive)
-
sendToSink
public static <T> void sendToSink(java.util.Iterator<T> iter, Sink<T> sink)Send the elements of the iterator to a sink - consumes the iterator
-
iter
public static <T> Iter<T> iter(java.util.Collection<T> collection)
-
iter
public static <T> Iter<T> iter(java.util.Iterator<T> iterator)
-
singletonIter
public static <T> Iter<T> singletonIter(T item)
-
nullIter
public static <T> Iter<T> nullIter()
-
materialize
public static <T> java.util.Iterator<T> materialize(java.util.Iterator<T> iter)
Materialize an iterator, that is, force it to run now - useful in debugging or when iteration may modify underlying datastructures.
-
concat
public static <T> Iter<T> concat(java.util.Iterator<T> iter1, java.util.Iterator<T> iter2)
-
first
public static <T> T first(java.util.Iterator<T> iter)
Return the first element of an iterator or null if no such element.- Parameters:
iter-- Returns:
- An item or null.
-
first
public static <T> T first(java.util.Iterator<T> iter, java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element.
-
firstIndex
public static <T> int firstIndex(java.util.Iterator<T> iter, java.util.function.Predicate<T> filter)Skip to the first element meeting a condition and return that element's index (zero-based).
-
last
public static <T> T last(java.util.Iterator<T> iter)
Return the last element or null, if no elements. This operation consumes the iterator.
-
last
public static <T> T last(java.util.Iterator<T> iter, java.util.function.Predicate<? super T> filter)Return the last element satisfying a predicate. This operation consumes the whole iterator.
-
lastIndex
public static <T> int lastIndex(java.util.List<T> list, java.util.function.Predicate<? super T> filter)Find the last occurrence, defined by a predicate, in a list.
-
forEach
public void forEach(java.util.function.Consumer<T> action)
Apply the Consumer to each element of the iterator
-
toSet
public java.util.Set<T> toSet()
Consume theIterand produce aSet
-
toList
public java.util.List<T> toList()
Consume theIterand produce aList
-
first
public T first()
-
last
public T last()
-
first
public T first(java.util.function.Predicate<T> filter)
Skip to the first element meeting a condition and return that element.
-
firstIndex
public int firstIndex(java.util.function.Predicate<T> filter)
Skip to the first element meeting a condition and return that element's index (zero-based).
-
allMatch
public boolean allMatch(java.util.function.Predicate<? super T> predicate)
-
anyMatch
public boolean anyMatch(java.util.function.Predicate<? super T> predicate)
-
noneMatch
public boolean noneMatch(java.util.function.Predicate<? super T> predicate)
-
findFirst
public java.util.Optional<T> findFirst(java.util.function.Predicate<? super T> predicate)
-
map
public <R> Iter<R> map(java.util.function.Function<T,R> converter)
Map each element using given function
-
flatMap
public <R> Iter<R> flatMap(java.util.function.Function<T,java.util.Iterator<R>> converter)
FlatMap each element using given function of element to iterator of mapped elements.s
-
operate
public Iter<T> operate(java.util.function.Consumer<T> action)
Apply an action to everything in the stream, yielding a stream of the original items.
-
foldLeft
public <R> R foldLeft(R initial, Iter.Folder<T,R> accumulator)
-
foldRight
public <R> R foldRight(R initial, Iter.Folder<T,R> accumulator)
-
reduce
public java.util.Optional<T> reduce(java.util.function.BinaryOperator<T> accumulator)
Reduce. This reduce is fold-left (take first element, apply to rest of list)
-
collect
public <R> R collect(java.util.function.Supplier<R> supplier, java.util.function.BiConsumer<R,T> accumulator)SeeStream.collect(Supplier, BiConsumer, BiConsumer), except without theBiConsumer<R, R> combiner
-
collect
public <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
SeeStream.collect(Collector)
-
apply
public void apply(java.util.function.Consumer<T> action)
Apply an action to every element of an iterator
-
append
public Iter<T> append(java.util.Iterator<T> iter)
Join on anIterator.. If there are going to be many iterators, it is better to create anIteratorConcatand .add each iterator. The overheads are much lower.
-
takeWhile
public Iter<T> takeWhile(java.util.function.Predicate<T> predicate)
Create anItersuch that it yields elements while a predicate test on the elements is true, end the iteration.- See Also:
filter(Predicate)
-
takeUntil
public Iter<T> takeUntil(java.util.function.Predicate<T> predicate)
Create anItersuch that it yields elements until a predicate test on the elements becomes true, end the iteration.- See Also:
filter(Predicate)
-
dropWhile
public Iter<T> dropWhile(java.util.function.Predicate<T> predicate)
Create anItersuch that elements from the front while a predicate test become true are dropped then return all remaining elements are iterated over. The first element where the predicted becomes true is the first element of the returned iterator.
-
dropUntil
public Iter<T> dropUntil(java.util.function.Predicate<T> predicate)
Create anItersuch that elements from the front until a predicate test become true are dropped then return all remaining elements are iterated over. The first element where the predicate becomes true is the first element of the returned iterator.
-
count
public long count()
Count the iterator (this is destructive on the iterator)
-
distinct
public Iter<T> distinct()
Return anIterthat will see each element of the underlying iterator only once. Note that this need working memory to remember the elements already seen.
-
distinctAdjacent
public Iter<T> distinctAdjacent()
Remove adjacent duplicates. This operation does not need working memory to remember the all elements already seen, just a slot for the last element seen.
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<T>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<T>
-
-