T - the type of element over which an instance of Iter iterates,public class Iter<T> extends Object implements Iterator<T>
Iterators.
This class provides functionality similar to Stream
except 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 class
Iter provides methods to call on an iterator.
import static org.apache.jena.atlas.iterator.Iter.iter ; iter(iterator).map(...).filter(...)
| Modifier and Type | Class and Description |
|---|---|
static interface |
Iter.Folder<X,Y> |
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
allMatch(Iterator<T> iter,
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)
|
boolean |
allMatch(Predicate<? super T> predicate) |
static <T> boolean |
anyMatch(Iterator<T> iter,
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)
|
boolean |
anyMatch(Predicate<? super T> predicate) |
static <T> Iterator<T> |
append(Iterator<? extends T> iter1,
Iterator<? extends T> iter2)
Join two iterators.
|
Iter<T> |
append(Iterator<T> iter)
Join on an
Iterator.. |
void |
apply(Consumer<T> action)
Apply an action to every element of an iterator
|
static <T> void |
apply(Iterator<? extends T> stream,
Consumer<T> action)
Act on elements of an iterator.
|
static <T> Stream<T> |
asStream(Iterator<T> iterator) |
static <T> Stream<T> |
asStream(Iterator<T> iterator,
boolean parallel) |
static <T> String |
asString(Iterator<T> stream,
CharSequence sep,
CharSequence prefix,
CharSequence suffix)
Create a string from an iterator, using the separator, prefix and suffix.
|
static <T> String |
asString(Iterator<T> stream,
String sep)
Create a string from an iterator, using the separator.
|
static <T> void |
close(Iterator<T> iter) |
<R,A> R |
collect(Collector<? super T,A,R> collector)
|
static <T,R,A> R |
collect(Iterator<T> iter,
Collector<? super T,A,R> collector)
|
static <T,R> R |
collect(Iterator<T> iter,
Supplier<R> supplier,
BiConsumer<R,? super T> accumulator)
See
Stream.collect(Supplier, BiConsumer, BiConsumer), except without the BiConsumer<R, R> combiner |
<R> R |
collect(Supplier<R> supplier,
BiConsumer<R,T> accumulator)
See
Stream.collect(Supplier, BiConsumer, BiConsumer), except without the BiConsumer<R, R> combiner |
static <T> Iter<T> |
concat(Iter<T> iter1,
Iter<T> iter2)
An
Iter of 2 Iter's |
static <T> Iter<T> |
concat(Iterator<T> iter1,
Iterator<T> iter2)
An
Iterator of 2 Iterator's. |
static <T> void |
consume(Iterator<T> iterator)
Consume the iterator
|
long |
count()
Count the iterator (this is destructive on the iterator)
|
static <T> long |
count(Iterator<T> iterator)
Count the iterator (this is destructive on the iterator)
|
static <T> Iterator<T> |
debug(Iterator<T> stream)
Print an iterator to stdout, return a copy of the iterator.
|
static <T> Iterator<T> |
debug(PrintStream out,
Iterator<T> stream)
Print an iterator, return a copy of the iterator.
|
Iter<T> |
distinct()
Return an
Iter that will see each element of the underlying iterator only once. |
static <T> Iterator<T> |
distinct(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> Iterator<T> |
distinctAdjacent(Iterator<T> iter)
Remove adjacent duplicates.
|
static <T> Iterator<T> |
dropUntil(Iterator<T> iter,
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> |
dropUntil(Predicate<T> predicate)
Create an
Iter such that elements from the front until
a predicate test become true are dropped then return all remaining elements
are iterated over. |
static <T> Iterator<T> |
dropWhile(Iterator<T> iter,
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.
|
Iter<T> |
dropWhile(Predicate<T> predicate)
Create an
Iter such that elements from the front while
a predicate test become true are dropped then return all remaining elements
are iterated over. |
static <T> boolean |
every(Iterator<? extends T> iter,
Predicate<T> predicate)
|
boolean |
every(Predicate<T> predicate)
Return true if every element satisfies a predicate
|
static <T> Iterator<T> |
filter(Iterator<? extends T> stream,
Predicate<T> filter) |
Iter<T> |
filter(Predicate<T> filter)
Filter by predicate
|
static <T> Optional<T> |
findAny(Iterator<T> iter,
Predicate<? super T> predicate)
Return an Optional with an element of an iterator that matches the predicate.
|
Optional<T> |
findAny(Predicate<? super T> predicate) |
static <T> Optional<T> |
findFirst(Iterator<T> iter,
Predicate<? super T> predicate)
Return an Optional with the first element of an iterator that matches the predicate.
|
Optional<T> |
findFirst(Predicate<? super T> predicate) |
T |
first() |
static <T> T |
first(Collection<T> collection,
Predicate<T> filter)
Deprecated.
Use Java8 Streams
|
static <T> T |
first(Iterator<T> iter)
Return the first element of an iterator or null if no such element.
|
static <T> T |
first(Iterator<T> iter,
Predicate<T> filter)
Skip to the first element meeting a condition and return that element.
|
T |
first(Predicate<T> filter)
Skip to the first element meeting a condition and return that element.
|
static <T> int |
firstIndex(Collection<T> collection,
Predicate<T> filter)
Deprecated.
Use Java8 Streams
|
static <T> int |
firstIndex(Iterator<T> iter,
Predicate<T> filter)
Skip to the first element meeting a condition and return that element's index (zero-based).
|
int |
firstIndex(Predicate<T> filter)
Skip to the first element meeting a condition and return that element's index (zero-based).
|
<R> Iter<R> |
flatMap(Function<T,Iterator<R>> converter)
FlatMap each element using given function of element to iterator of mapped elements.s
|
static <T,R> Iterator<R> |
flatMap(Iterator<T> iter,
Function<T,Iterator<R>> mapper)
Apply a function to every element of an iterator, to produce possibly multiple mapping each time.
|
static <T,R> R |
foldLeft(Iterator<? extends T> stream,
R value,
Iter.Folder<T,R> function) |
<R> R |
foldLeft(R initial,
Iter.Folder<T,R> accumulator) |
static <T,R> R |
foldRight(Iterator<? extends T> stream,
R value,
Iter.Folder<T,R> function) |
<R> R |
foldRight(R initial,
Iter.Folder<T,R> accumulator) |
void |
forEach(Consumer<T> action)
Apply the Consumer to each element of the iterator
|
static <T> void |
forEach(Iterator<T> iter,
Consumer<T> action)
Shorter form of "forEachRemaining"
|
boolean |
hasNext() |
static <T> Iter<T> |
iter(Collection<T> collection) |
static <T> Iter<T> |
iter(Iter<T> iter) |
static <T> Iter<T> |
iter(Iterator<T> iterator) |
static <T> Iterator<T> |
iterator(Iterator<? extends T> iterator)
Create another iterator without risk of concurrent modification
exceptions.
|
T |
last() |
static <T> T |
last(Collection<T> collection,
Predicate<T> filter)
Deprecated.
Use Java8 Streams
|
static <T> T |
last(Iterator<T> iter)
Return the last element or null, if no elements.
|
static <T> T |
last(Iterator<T> iter,
Predicate<T> filter)
Return the last element satisfying a predicate.
|
T |
last(Predicate<T> filter)
Return the last element satisfying a predicate.
|
static <T> int |
lastIndex(Collection<T> collection,
Predicate<T> filter)
Deprecated.
Use Java8 Streams
|
static <T> int |
lastIndex(Iterator<T> iter,
Predicate<T> filter)
Return the index of the last element satisfying a predicate (zero-based).
|
int |
lastIndex(Predicate<T> filter)
Return the index of the last element satisfying a predicate (zero-based).
|
static <X> Iterator<X> |
limit(Iterator<X> iterator,
long limit)
Return an iterator that is limited to the given number of elements.
|
Iter<T> |
limit(long N)
Limit the number of elements.
|
static <T> Iterator<T> |
log(Iterator<T> stream)
Print an iterator to stdout, return a copy of the iterator.
|
static <T> Iterator<T> |
log(PrintStream out,
Iterator<T> stream)
Print an iterator to stdout, return a copy of the iterator.
|
<R> Iter<R> |
map(Function<T,R> converter)
Map each element using given function
|
static <T,R> Iterator<R> |
map(Iterator<? extends T> stream,
Function<T,R> converter)
Apply a function to every element of an iterator, transforming it
from a
T to an R. |
static <T,R> List<R> |
map(List<? extends T> list,
Function<T,R> converter)
Deprecated.
Use Java8 Streams
|
static <T> Iterator<T> |
materialize(Iterator<T> iter)
Materialize an iterator, that is, force it to run now - useful in
debugging or when iteration may modify underlying datastructures.
|
Optional<T> |
max(Comparator<T> comparator) |
static <T> Optional<T> |
max(Iterator<T> iter,
Comparator<T> comparator) |
Optional<T> |
min(Comparator<T> comparator) |
static <T> Optional<T> |
min(Iterator<T> iter,
Comparator<T> comparator) |
T |
next() |
static <T> boolean |
noneMatch(Iterator<T> iter,
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)
|
boolean |
noneMatch(Predicate<? super T> predicate) |
static <T> Iterator<T> |
notFilter(Iterator<? extends T> stream,
Predicate<T> filter) |
static <T> Iter<T> |
nullIter() |
static <T> Iterator<T> |
nullIterator() |
Iter<T> |
operate(Consumer<T> action)
Apply an action to everything in the stream, yielding a stream of the
original items.
|
static <T> Iterator<T> |
operate(Iterator<? extends T> stream,
Consumer<T> action)
Apply an action to everything in stream, yielding a stream of the
same items.
|
static <T> void |
print(Iterator<T> stream)
Print an iterator (destructive)
|
static <T> void |
print(PrintStream out,
Iterator<T> stream)
Print an iterator (destructive)
|
static <T> Iterator<T> |
printWrapper(Iterator<? extends T> stream)
Print an iterator as it gets used - this adds a printing wrapper
|
static <T> Iterator<T> |
printWrapper(PrintStream out,
Iterator<? extends T> stream)
Print an iterator as it gets used - this adds a printing wrapper
|
Optional<T> |
reduce(BinaryOperator<T> accumulator)
Reduce.
|
static <T> Optional<T> |
reduce(Iterator<T> iter,
BinaryOperator<T> accumulator) |
static <T> T |
reduce(Iterator<T> iter,
T identity,
BinaryOperator<T> accumulator) |
T |
reduce(T identity,
BinaryOperator<T> accumulator) |
void |
remove() |
Iter<T> |
removeNulls()
Remove nulls
|
static <T> Iterator<T> |
removeNulls(Iterator<T> iter)
Remove nulls from an iterator
|
static <T> void |
sendToSink(Iterable<T> stream,
Sink<T> sink)
Deprecated.
|
static <T> void |
sendToSink(Iterator<T> iter,
Sink<T> sink)
Send the elements of the iterator to a sink - consumes the iterator
|
void |
sendToSink(Sink<T> sink) |
static <T> Iterator<T> |
singleton(T item) |
static <T> Iter<T> |
singletonIter(T item) |
static <X> Iterator<X> |
skip(Iterator<X> iterator,
long limit)
Skip over a number of elements of an iterator
|
Iter<T> |
skip(long N)
Skip over a number of elements.
|
static <T> boolean |
some(Iterator<T> iter,
Predicate<? super T> predicate)
|
boolean |
some(Predicate<T> filter)
Return true if some element satisfies a predicate
|
static int |
step(Iterator<?> iter,
int steps)
Step forward up to
steps places. |
Iter<T> |
take(int N)
Return an Iter that yields at most the first N items
|
static <T> List<T> |
take(Iterator<T> iter,
int N)
Take the first N elements of an iterator - stop early if too few
|
static <T> Iterator<T> |
takeUntil(Iterator<T> iter,
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> |
takeUntil(Predicate<T> predicate)
Create an
Iter such that it yields elements until a predicate test on
the elements becomes true, end the iteration. |
static <T> Iterator<T> |
takeWhile(Iterator<T> iter,
Predicate<T> predicate)
Create an iterator such that it yields elements while a predicate test on
the elements is true, end the iteration.
|
Iter<T> |
takeWhile(Predicate<T> predicate)
Create an
Iter such that it yields elements while a predicate test on
the elements is true, end the iteration. |
List<T> |
toList()
Consume the
Iter and produce a List |
static <T> List<T> |
toList(Iterator<? extends T> stream)
Collect an iterator into a list.
|
Set<T> |
toSet()
Consume the
Iter and produce a Set |
static <T> Set<T> |
toSet(Iterator<? extends T> stream)
Collect an iterator into a set.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic static <T> void forEach(Iterator<T> iter, Consumer<T> action)
public static <T> Iterator<T> singleton(T item)
public static <T> Iterator<T> nullIterator()
public static <T> List<T> toList(Iterator<? extends T> stream)
public static <T> Iterator<T> iterator(Iterator<? extends T> iterator)
public static <T,R> R foldLeft(Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)
public static <T,R> R foldRight(Iterator<? extends T> stream, R value, Iter.Folder<T,R> function)
public static <T> Optional<T> reduce(Iterator<T> iter, BinaryOperator<T> accumulator)
public static <T> T reduce(Iterator<T> iter, T identity, BinaryOperator<T> accumulator)
public static <T> Optional<T> min(Iterator<T> iter, Comparator<T> comparator)
public static <T> Optional<T> max(Iterator<T> iter, Comparator<T> comparator)
public static <T,R> R collect(Iterator<T> iter, Supplier<R> supplier, BiConsumer<R,? super T> accumulator)
Stream.collect(Supplier, BiConsumer, BiConsumer), except without the BiConsumer<R, R> combinerpublic static <T> void apply(Iterator<? extends T> stream, Consumer<T> action)
map(Iterator, Function)public static <T> Iterator<T> notFilter(Iterator<? extends T> stream, Predicate<T> filter)
@Deprecated public static <T> boolean every(Iterator<? extends T> iter, Predicate<T> predicate)
public static <T> boolean allMatch(Iterator<T> iter, Predicate<? super T> predicate)
@Deprecated public static <T> boolean some(Iterator<T> iter, Predicate<? super T> predicate)
public static <T> boolean anyMatch(Iterator<T> iter, Predicate<? super T> predicate)
public static <T> boolean noneMatch(Iterator<T> iter, Predicate<? super T> predicate)
public static <T> Optional<T> findFirst(Iterator<T> iter, Predicate<? super T> predicate)
Optional.empty if none match.
Reads the iterator until the first match.public static <T> Optional<T> findAny(Iterator<T> iter, Predicate<? super T> predicate)
Optional.empty if none match.
The element returned is not specified by the API contract.public static <T,R> Iterator<R> map(Iterator<? extends T> stream, Function<T,R> converter)
T to an R.@Deprecated public static <T,R> List<R> map(List<? extends T> list, Function<T,R> converter)
public static <T,R> Iterator<R> flatMap(Iterator<T> iter, Function<T,Iterator<R>> mapper)
Stream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)public static <T> Iterator<T> operate(Iterator<? extends T> stream, Consumer<T> action)
public static <T> Iterator<T> printWrapper(Iterator<? extends T> stream)
public static <T> Iterator<T> printWrapper(PrintStream out, Iterator<? extends T> stream)
public static <T> Iterator<T> append(Iterator<? extends T> iter1, Iterator<? extends T> iter2)
IteratorConcat explicitly and add each iterator.public static <T> Iterator<T> distinct(Iterator<T> iter)
public static <T> Iterator<T> distinctAdjacent(Iterator<T> iter)
public static <T> Iterator<T> removeNulls(Iterator<T> iter)
public static int step(Iterator<?> iter, int steps)
steps places.
steps places with no overshoot.
The iterator can be used afterwards.public static <T> List<T> take(Iterator<T> iter, int N)
limit(Iterator, long)public static <T> Iterator<T> takeWhile(Iterator<T> iter, Predicate<T> predicate)
filter(Iterator, Predicate)public static <T> Iterator<T> takeUntil(Iterator<T> iter, Predicate<T> predicate)
filter(Iterator, Predicate)public static <T> Iterator<T> dropWhile(Iterator<T> iter, Predicate<T> predicate)
public static <T> Iterator<T> dropUntil(Iterator<T> iter, Predicate<T> predicate)
public static <X> Iterator<X> limit(Iterator<X> iterator, long limit)
take(Iterator, int)public static <X> Iterator<X> skip(Iterator<X> iterator, long limit)
public static <T> long count(Iterator<T> iterator)
public static <T> void consume(Iterator<T> iterator)
public static <T> String asString(Iterator<T> stream, String sep)
public static <T> String asString(Iterator<T> stream, CharSequence sep, CharSequence prefix, CharSequence suffix)
public static <T> void close(Iterator<T> iter)
public static <T> Iterator<T> log(Iterator<T> stream)
debug(java.util.Iterator<T>) for an operation to print as the
iterator is used.public static <T> Iterator<T> log(PrintStream out, Iterator<T> stream)
debug(java.util.Iterator<T>) for an operation to print as the
iterator is used.public static <T> Iterator<T> debug(Iterator<T> stream)
log(java.util.Iterator<T>) for
an operation to print now.public static <T> Iterator<T> debug(PrintStream out, Iterator<T> stream)
public static <T> void print(Iterator<T> stream)
public static <T> void print(PrintStream out, Iterator<T> stream)
public static <T> void sendToSink(Iterator<T> iter, Sink<T> sink)
@Deprecated public static <T> void sendToSink(Iterable<T> stream, Sink<T> sink)
public static <T> Iter<T> iter(Collection<T> collection)
public static <T> Iter<T> singletonIter(T item)
public static <T> Iter<T> nullIter()
public static <T> Iterator<T> materialize(Iterator<T> iter)
public static <T> T first(Iterator<T> iter)
iter - public static <T> T first(Iterator<T> iter, Predicate<T> filter)
@Deprecated public static <T> T first(Collection<T> collection, Predicate<T> filter)
public static <T> int firstIndex(Iterator<T> iter, Predicate<T> filter)
@Deprecated public static <T> int firstIndex(Collection<T> collection, Predicate<T> filter)
public static <T> T last(Iterator<T> iter)
public static <T> T last(Iterator<T> iter, Predicate<T> filter)
@Deprecated public static <T> T last(Collection<T> collection, Predicate<T> filter)
public static <T> int lastIndex(Iterator<T> iter, Predicate<T> filter)
@Deprecated public static <T> int lastIndex(Collection<T> collection, Predicate<T> filter)
public T first()
public T last()
public T first(Predicate<T> filter)
public int firstIndex(Predicate<T> filter)
public T last(Predicate<T> filter)
public int lastIndex(Predicate<T> filter)
public boolean every(Predicate<T> predicate)
public <R> Iter<R> flatMap(Function<T,Iterator<R>> converter)
public Iter<T> operate(Consumer<T> action)
public <R> R foldLeft(R initial,
Iter.Folder<T,R> accumulator)
public <R> R foldRight(R initial,
Iter.Folder<T,R> accumulator)
public Optional<T> reduce(BinaryOperator<T> accumulator)
public T reduce(T identity, BinaryOperator<T> accumulator)
public Optional<T> min(Comparator<T> comparator)
public Optional<T> max(Comparator<T> comparator)
public <R> R collect(Supplier<R> supplier, BiConsumer<R,T> accumulator)
Stream.collect(Supplier, BiConsumer, BiConsumer), except without the BiConsumer<R, R> combinerpublic Iter<T> append(Iterator<T> iter)
Iterator..
If there are going to be many iterators, uit is better to create an IteratorConcat
and .add each iterator. The overheads are much lower.public Iter<T> takeWhile(Predicate<T> predicate)
Iter such that it yields elements while a predicate test on
the elements is true, end the iteration.filter(Predicate)public Iter<T> takeUntil(Predicate<T> predicate)
Iter such that it yields elements until a predicate test on
the elements becomes true, end the iteration.filter(Predicate)public Iter<T> dropWhile(Predicate<T> predicate)
Iter 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.public Iter<T> dropUntil(Predicate<T> predicate)
Iter 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.public long count()
public Iter<T> distinct()
Iter that will see each element of the underlying iterator only once.
Note that this need working memory to remember the elements already seen.public Iter<T> distinctAdjacent()
Licenced under the Apache License, Version 2.0