提交 87c74aaa 编写于 作者: K kohsuke

more iterator-related convenience methods

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15824 71c3de6d-444a-0410-be80-ed276b4c234a
上级 0307f130
......@@ -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();
}
};
}
};
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册