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> 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) |
String |
asString() |
static <T> String |
asString(Iterable<T> stream) |
static <T> String |
asString(Iterable<T> stream,
AccString<T> formatter) |
static <T> String |
asString(Iterable<T> stream,
String sep) |
static <T> String |
asString(Iterator<T> stream) |
static <T> String |
asString(Iterator<T> stream,
AccString<T> formatter) |
static <T> String |
asString(Iterator<T> stream,
String sep) |
String |
asString(String sep) |
static <T> void |
close(Iterator<T> iter) |
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 {:@code 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> stream,
Predicate<T> filter)
Return true if every element of stream passes the filter (reads the
stream until the first element not passing the filter)
|
boolean |
every(Predicate<T> predciate)
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
|
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(Iterable<? extends T> stream,
Iter.Folder<T,R> function,
R value) |
static <T,R> R |
foldLeft(Iterator<? extends T> stream,
Iter.Folder<T,R> function,
R value) |
static <T,R> R |
foldRight(Iterable<? extends T> stream,
Iter.Folder<T,R> function,
R value) |
static <T,R> R |
foldRight(Iterator<? extends T> stream,
Iter.Folder<T,R> function,
R value) |
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 <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.
|
T |
next() |
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
|
<R> R |
reduce(Accumulate<T,R> aggregator)
Reduce by aggregator.
|
static <T,R> R |
reduce(Iterable<? extends T> stream,
Accumulate<T,R> aggregator)
Reduce by aggregator.
|
static <T,R> R |
reduce(Iterator<? extends T> stream,
Accumulate<T,R> aggregator)
Reduce by aggregator.
|
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)
Send the elements of the iterable to a sink
|
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 <T> boolean |
some(Iterator<? extends T> stream,
Predicate<T> filter)
Return true if one or more elements of stream passes the filter (reads
the stream to first element passing the filter)
|
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> 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(Iterable<? extends T> stream, Iter.Folder<T,R> function, R value)
public static <T,R> R foldLeft(Iterator<? extends T> stream, Iter.Folder<T,R> function, R value)
public static <T,R> R foldRight(Iterable<? extends T> stream, Iter.Folder<T,R> function, R value)
public static <T,R> R foldRight(Iterator<? extends T> stream, Iter.Folder<T,R> function, R value)
public static <T,R> R reduce(Iterable<? extends T> stream, Accumulate<T,R> aggregator)
public static <T,R> R reduce(Iterator<? extends T> stream, Accumulate<T,R> aggregator)
public 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)
public static <T> boolean every(Iterator<? extends T> stream, Predicate<T> filter)
public static <T> boolean some(Iterator<? extends T> stream, Predicate<T> filter)
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.
public static <T> List<T> take(Iterator<T> iter, int N)
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 <T> long count(Iterator<T> iterator)
public static <T> void consume(Iterator<T> iterator)
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)
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> predciate)
public <R> Iter<R> flatMap(Function<T,Iterator<R>> converter)
public Iter<T> operate(Consumer<T> action)
public <R> R reduce(Accumulate<T,R> aggregator)
public 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 String asString()
public Iter<T> distinct()
public Iter<T> distinctAdjacent()
Licenced under the Apache License, Version 2.0