Package eu.bandm.tools.util.java
Class Iterators
java.lang.Object
eu.bandm.tools.util.java.Iterators
Library of combinators for classes implementing
Iterator
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
(package private) static class
static class
An iterator which allows arbitrary deep look-ahead for an underlying iterator.static class
Visitor which performs the methodIterators.Pairwise.first(Object)
for the first element of an Iterable; afterwards the methodIterators.Pairwise.pairwise(Object,Object)
for each pair of adjacent elements, and at last the methodIterators.Pairwise.last(Object)
.static interface
(package private) static class
static class
Visitor which performs the methodIterators.Triplewise.action(Object,Object,Object)
for triples of adjacent elements of an Iterable. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E,
F> Iterator<F> static <A> Iterator<A>
cacheHasNext
(Iterator<A> i) static <A> Iterator<A>
Forgets a wildcard in the element type of a given iterator.static <A,
B> Iterator<B> comprehend
(Iterator<A> gen, Function<? super A, ? extends Iterator<B>> fun) Deprecated.use streams insteadstatic <A,
B> Iterator<B> comprehend
(Iterator<A> gen, Predicate<? super A> filter, Function<? super A, ? extends B> map) Deprecated.use streams insteadstatic <E> Iterator<E>
Returns an iterator consisting of the combined elements of two given iterators in order.static <E> Iterator<E>
Returns an iterator consisting of the given first element preceding the remaining elements of a given iterator.static <A> Iterator<A>
static <A> void
elementwise
(Consumer<? super A> sink, Iterator<A> it) static <E> Iterator<E>
empty()
Returns an iterator consisting of no elements.static <E> Iterator<E>
Returns an iterator consisting of the remaining elements of a given iterator that match the given predicate.static <A,
B> Iterator<A> filterWithConstraint
(BiPredicate<? super A, ? super B> rel, Iterator<A> things, Iterator<B> constraints) static <E> Iterator<E>
Returns an iterator consisting of the combined elements of all iterators returned by a given iterator in order.static <A> Iterators.LookaheadIterator<A>
static <A,
B> Iterator<B> Returns an iterator consisting of the results of applying the given function to the remaining elements of a given iterator.static <A> Iterator<A>
merge
(Comparator<? super A> order, boolean removeDuplicates, Iterator<? extends A> left, Iterator<? extends A> right) static <E> Iterator<E>
of
(E... things) Returns an iterator consisting of exactly the given elements.static <E> Iterator<E>
singleton
(E value) Returns an iterator consisting of exactly one given element.static <A> Iterator<A>
static <A> Iterator<A>
unmodifiableIterator
(Iterator<A> i)
-
Method Details
-
cast
Forgets a wildcard in the element type of a given iterator.- Parameters:
iterator
- an iterator- Returns:
- the same iterator
-
empty
Returns an iterator consisting of no elements.- Type Parameters:
E
- the type of elements returned by the returned iterator- Returns:
- an iterator that has no elements
-
singleton
Returns an iterator consisting of exactly one given element. The element is not removable.- Type Parameters:
E
- the type of elements returned by the returned iterator- Parameters:
value
- the single element of the returned iterator- Returns:
- an iterator that has exactly the given element
-
of
Returns an iterator consisting of exactly the given elements. Elements are not removable.- Type Parameters:
E
- the type of elements returned by the returned iterator- Parameters:
things
- the elements of the returned iterator- Returns:
- an iterator that has exactly the given elements
-
cons
Returns an iterator consisting of the given first element preceding the remaining elements of a given iterator. The first element is not removable. Further removal requests are passed through to the underlying iterator.- Type Parameters:
E
- the type of elements returned by the returned iterator- Parameters:
first
- the first elementrest
- the iterator of the succeeding elements- Returns:
- an iterator that returns the first element followed by the
remaining elements of
rest
- Throws:
NullPointerException
- ifrest == null
-
concat
Returns an iterator consisting of the combined elements of two given iterators in order. Removal requests are passed through to the underlying iterators.- Type Parameters:
E
- the type of elements returned by the returned iterator- Parameters:
first
- the first iterator to consult for elementssecond
- the second iterator to consult for elements- Returns:
- an iterator that returns all remaining elements of
first
, followed by all remaining elements ofsecond
- Throws:
NullPointerException
- iffirst == null
orsecond == null
-
flatten
Returns an iterator consisting of the combined elements of all iterators returned by a given iterator in order. Removal requests are passed through to the underlying iterators.- Type Parameters:
E
- the type of elements returned by the returned iterator- Parameters:
iterators
- the iterators to be combined- Returns:
- the combined interator
- Throws:
NullPointerException
- ifiterators == null
or one in the list is==null
.
-
bind
@Undocumented public static <E,F> Iterator<F> bind(Function<? super E, ? extends Iterator<? extends F>> fun, Iterator<E> things) -
filter
Returns an iterator consisting of the remaining elements of a given iterator that match the given predicate. Removal requests are passed through to the underlying iterator. -
map
Returns an iterator consisting of the results of applying the given function to the remaining elements of a given iterator. Removal requests are passed through to the underlying iterator. -
comprehend
@Deprecated(since="0.0") public static <A,B> Iterator<B> comprehend(Iterator<A> gen, Predicate<? super A> filter, Function<? super A, ? extends B> map) Deprecated.use streams insteadFirst apply filter, than map, and collect results. -
comprehend
@Deprecated(since="0.0") public static <A,B> Iterator<B> comprehend(Iterator<A> gen, Function<? super A, ? extends Iterator<B>> fun) Deprecated.use streams insteadApply function and collect results. -
unmodifiableIterator
-
lookahead
@Undocumented public static <A> Iterators.LookaheadIterator<A> lookahead(Iterator<? extends A> things) -
merge
@Undocumented public static <A> Iterator<A> merge(Comparator<? super A> order, boolean removeDuplicates, Iterator<? extends A> left, Iterator<? extends A> right) -
filterWithConstraint
@Undocumented public static <A,B> Iterator<A> filterWithConstraint(BiPredicate<? super A, ? super B> rel, Iterator<A> things, Iterator<B> constraints) -
cacheHasNext
-
drop
-
take
-
elementwise
-