blob: 55e5985ee55e38ca58f34f1e1abe8b4477b68bc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package bjc.utils.funcutils;
import java.util.Iterator;
/**
* Utility methods for dealing with iterators.
*
* @author bjculkin
*
*/
public class IteratorUtils {
/**
* Convert an iterator to an iterable.
*
* @param itr
* The iterator to convert.
* @return An iterable that gives back that iterator.
*/
public static <E> Iterable<E> I(Iterator<E> itr) {
return () -> itr;
}
/**
* Convert an iterable to an iterator.
*
* @param itr
* The iterable to convert.
* @return The iterator from that iterable
*/
public static <E> Iterator<E> I(Iterable<E> itr) {
return itr.iterator();
}
}
|