com.link_intersystems.graph.tree.IterableTreeModel 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.stream.Stream;
/**
* A {@link TreeModel} that expands parents that are {@link Iterator}s or {@link Iterable}s.
*
* @author René Link {@literal }
*/
public class IterableTreeModel implements TreeModel {
@Override
public Stream extends T> getChildren(T parent) {
if (parent instanceof Iterable) {
return Iterators.toStream(((Iterable extends T>) parent).iterator());
}
if (parent instanceof Iterator) {
return Iterators.toStream((Iterator extends T>) parent);
}
return Stream.empty();
}
}