Package hudson.util
Class Iterators
- java.lang.Object
-
- hudson.util.Iterators
-
public class Iterators extends Object
VariosIteratorimplementations.- Author:
- Kohsuke Kawaguchi
- See Also:
AdaptedIterator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIterators.CountingPredicate<T>static classIterators.DuplicateFilterIterator<T>Remove duplicates from another iterator.static classIterators.FilterIterator<T>Creates a filtered view of another iterator.static classIterators.FlattenIterator<U,T>Produces {A,B,C,D,E,F} from {{A,B},{C},{},{D,E,F}}.
-
Constructor Summary
Constructors Constructor Description Iterators()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Iterable<T>cast(Iterable<? extends T> itr)CastsIterableby taking advantage of its covariant-ness.static <T> Iterator<T>cast(Iterator<? extends T> itr)CastsIteratorby taking advantage of its covariant-ness.static <T> Iterator<T>empty()Returns the empty iterator.static <T> Iterator<T>limit(Iterator<? extends T> base, Iterators.CountingPredicate<? super T> filter)Returns the elements in the base iterator until it hits any element that doesn't satisfy the filter.static <T> Iterator<T>readOnly(Iterator<T> itr)Creates a read-only mutator that disallowsIterator.remove().static <T> Iterable<T>removeDups(Iterable<T> base)Filters another iterator by eliminating duplicates.static <T> Iterator<T>removeDups(Iterator<T> iterator)Filters another iterator by eliminating duplicates.static <T> Iterator<T>removeNull(Iterator<T> itr)Wraps another iterator and throws away nulls.static <T> Iterable<T>reverse(List<T> lst)Returns theIterablethat lists items in the reverse order.static List<Integer>reverseSequence(int start, int end)static List<Integer>reverseSequence(int start, int end, int step)The short cut forreverse(sequence(start,end,step)).static List<Integer>sequence(int start, int end)static List<Integer>sequence(int start, int end, int step)Returns a list that represents [start,end).static <T> Iterable<T>sequence(Iterable<? extends T>... iterables)static <T> Iterator<T>sequence(Iterator<? extends T>... iterators)static voidskip(Iterator<?> iterator, int count)Callsnext()oniterator, eithercounttimes or untilhasNext()returnsfalse, whichever comes first.static <U,T extends U>
Iterator<T>subType(Iterator<U> itr, Class<T> type)Returns anIteratorthat only returns items of the given subtype.static <T> Iterable<T>wrap(Iterable<T> base)Returns anIterablethat lists items in the normal order but which hides the base iterator implementation details.
-
-
-
Method Detail
-
empty
public static <T> Iterator<T> empty()
Returns the empty iterator.
-
reverse
public static <T> Iterable<T> reverse(List<T> lst)
Returns theIterablethat lists items in the reverse order.- Since:
- 1.150
-
wrap
public static <T> Iterable<T> wrap(Iterable<T> base)
Returns anIterablethat lists items in the normal order but which hides the base iterator implementation details.- Since:
- 1.492
-
sequence
public static List<Integer> sequence(int start, int end, int step)
Returns a list that represents [start,end). For example sequence(1,5,1)={1,2,3,4}, and sequence(7,1,-2)={7.5,3}- Since:
- 1.150
-
reverseSequence
public static List<Integer> reverseSequence(int start, int end, int step)
The short cut forreverse(sequence(start,end,step)).- Since:
- 1.150
-
cast
public static <T> Iterator<T> cast(Iterator<? extends T> itr)
CastsIteratorby taking advantage of its covariant-ness.
-
cast
public static <T> Iterable<T> cast(Iterable<? extends T> itr)
CastsIterableby taking advantage of its covariant-ness.
-
subType
public static <U,T extends U> Iterator<T> subType(Iterator<U> itr, Class<T> type)
Returns anIteratorthat only returns items of the given subtype.
-
readOnly
public static <T> Iterator<T> readOnly(Iterator<T> itr)
Creates a read-only mutator that disallowsIterator.remove().
-
removeNull
public static <T> Iterator<T> removeNull(Iterator<T> itr)
Wraps another iterator and throws away nulls.
-
sequence
@SafeVarargs public static <T> Iterable<T> sequence(Iterable<? extends T>... iterables)
-
removeDups
public static <T> Iterator<T> removeDups(Iterator<T> iterator)
Filters another iterator by eliminating duplicates.
-
removeDups
public static <T> Iterable<T> removeDups(Iterable<T> base)
Filters another iterator by eliminating duplicates.
-
sequence
@SafeVarargs public static <T> Iterator<T> sequence(Iterator<? extends T>... iterators)
-
limit
public static <T> Iterator<T> limit(Iterator<? extends T> base, Iterators.CountingPredicate<? super T> filter)
Returns the elements in the base iterator until it hits any element that doesn't satisfy the filter. Then the rest of the elements in the base iterator gets ignored.- Since:
- 1.485
-
skip
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void skip(@NonNull Iterator<?> iterator, int count)Callsnext()oniterator, eithercounttimes or untilhasNext()returnsfalse, whichever comes first.- Parameters:
iterator- some iteratorcount- a nonnegative count
-
-