mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-18 06:22:29 +00:00
more iterator-related convenience methods
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15824 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
0307f13050
commit
87c74aaa70
1 file changed
+35
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.ListIterator;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Varios {@link Iterator} implementations.
|
||||
@@ -203,6 +204,22 @@ public class Iterators {
|
||||
return reverseSequence(start,end,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts {@link Iterator} by taking advantage of its covariant-ness.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> Iterator<T> cast(Iterator<? extends T> itr) {
|
||||
return (Iterator)itr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts {@link Iterable} by taking advantage of its covariant-ness.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> Iterable<T> cast(Iterable<? extends T> itr) {
|
||||
return (Iterable)itr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a read-only mutator that disallows {@link Iterator#remove()}.
|
||||
*/
|
||||
@@ -221,4 +238,22 @@ public class Iterators {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@link Iterable} that iterates over all the given {@link Iterable}s.
|
||||
*
|
||||
* <p>
|
||||
* That is, this creates {A,B,C,D} from {A,B},{C,D}.
|
||||
*/
|
||||
public static <T> Iterable<T> sequence( final Iterable<? extends T>... iterables ) {
|
||||
return new Iterable<T>() {
|
||||
public Iterator<T> iterator() {
|
||||
return new FlattenIterator<T,Iterable<? extends T>>(Arrays.asList(iterables)) {
|
||||
protected Iterator<T> expand(Iterable<? extends T> iterable) {
|
||||
return cast(iterable).iterator();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user