Package net.sourceforge.pmd.util
Class IteratorUtil
java.lang.Object
net.sourceforge.pmd.util.IteratorUtil
Operations for dealing with
Iterators.- Author:
- Clément Fournier
- Since:
- 6.11.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNote, that this iterator doesn't support theremoveoperation.static class -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdvancentimes.static <T> booleanReturns whether all elements match the predicate.static <T> booleanReturns whether some element match the predicate.static <T> Iterable<T> asReversed(List<T> lst) static <T> Iterator<T> coerceWildcard(Iterator<? extends T> it) Coerce an iterator with a wildcard.static <T> Iterator<T> static intCounts the items in this iterator, exhausting it.static <T> Iterator<T> static <T> Iterator<T> Produce an iterator whose first element is the nth element of the given source.static <T> Iterator<@NonNull T> Remove the last n elements of the iterator.static <T> Iterator<T> static <T> Iterator<@NonNull T> filterNotNull(Iterator<? extends T> it) static <T,R> Iterator <R> flatMap(Iterator<? extends T> iter, Function<? super T, ? extends @Nullable Iterator<? extends R>> f) static <R> Iterator<R> flatMapWithSelf(Iterator<? extends R> iter, Function<? super R, ? extends @Nullable Iterator<? extends R>> f) Like flatMap, but yields each element of the input iterator before yielding the results of the mapper function.static <T> Iterator<@NonNull T> Returns an iterator that applies a stepping function to the previous value yielded.static <T> @Nullable TReturns the nth element of this iterator, or null if the iterator is shorter.static <T> Iterator<T> iterate(T... elements) static <T> @Nullable Tstatic <T,R> Iterator <R> static <T,R> Iterable <R> mapIterator(Iterable<? extends T> iter, Function<? super Iterator<? extends T>, ? extends Iterator<R>> mapper) Apply a transform on the iterator of an iterable.static <T,R> Iterator <@NonNull R> mapNotNull(Iterator<? extends T> it, Function<@NonNull ? super T, @Nullable ? extends R> mapper) static <T> booleanReturns whether no elements match the predicate.static <T> Iterator<T> static <T> Iterator<T> static <T> Iterator<T> singletonIterator(T value) static <T> Iterator<T> Limit the number of elements yielded by this iterator to the given number.static <T> Iterator<T> static <T> Iterable<T> toIterable(Iterator<T> it) static <T> List<T> static <T> List<@NonNull T> toNonNullList(Iterator<? extends @Nullable T> it) static <T> Stream<T> static <T> Stream<T>
-
Method Details
-
takeWhile
-
reverse
-
flatMap
-
flatMapWithSelf
public static <R> Iterator<R> flatMapWithSelf(Iterator<? extends R> iter, Function<? super R, ? extends @Nullable Iterator<? extends R>> f) Like flatMap, but yields each element of the input iterator before yielding the results of the mapper function. Null elements of the input iterator are both yielded by the returned iterator and passed to the stepper. If the stepper returns null, that result is ignored. -
filterNotNull
-
mapNotNull
-
filter
-
peek
-
map
-
mapIterator
public static <T,R> Iterable<R> mapIterator(Iterable<? extends T> iter, Function<? super Iterator<? extends T>, ? extends Iterator<R>> mapper) Apply a transform on the iterator of an iterable. -
iterate
-
concat
-
distinct
-
toList
-
toNonNullList
-
dropLast
Remove the last n elements of the iterator. This uses n elements as a lookahead. -
coerceWildcard
Coerce an iterator with a wildcard. This is safe because the Iterator interface is covariant (notListIteratorthough). -
toIterable
-
count
Counts the items in this iterator, exhausting it. -
last
-
getNth
Returns the nth element of this iterator, or null if the iterator is shorter.- Throws:
IllegalArgumentException- If n is negative
-
advance
Advancentimes. -
take
Limit the number of elements yielded by this iterator to the given number. -
drop
Produce an iterator whose first element is the nth element of the given source. -
generate
public static <T> Iterator<@NonNull T> generate(@Nullable T seed, Function<? super @NonNull T, ? extends @Nullable T> stepper) Returns an iterator that applies a stepping function to the previous value yielded. Iteration stops on the first null value returned by the stepper.- Type Parameters:
T- Type of values- Parameters:
seed- First value. If null then the iterator is emptystepper- Step function
-
anyMatch
Returns whether some element match the predicate. If empty thenfalseis returned. -
allMatch
Returns whether all elements match the predicate. If empty thentrueis returned. -
noneMatch
Returns whether no elements match the predicate. If empty thentrueis returned. -
singletonIterator
-
asReversed
-
toStream
-
toStream
-