com.link_intersystems.graph.tree.Iterators Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lis-commons-graph Show documentation
Show all versions of lis-commons-graph Show documentation
Link Intersystems Commons Graph (lis-commons-graph) is a collection of reusable software components
that provide support for graph and tree related programming tasks, such as models and search algorithms.
package com.link_intersystems.graph.tree;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* @author René Link {@literal }
*/
public class Iterators {
public static Stream toStream(Iterator iterator) {
Iterable iterable = () -> iterator;
return toStream(iterable);
}
public static Stream toStream(Iterable iterable) {
return StreamSupport.stream(iterable.spliterator(), false);
}
public static List toList(Iterable iterable) {
return toList(iterable.iterator());
}
public static List toList(Iterator iterator) {
return toStream(iterator).collect(Collectors.toList());
}
}