com.link_intersystems.graph.tree.FlatTreeModel 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.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* A {@link TreeModel} that flattens the tree structure for a given parent down to its leaves.
*
* E.g. if the base model describes the following tree:
*
*
* +-(B)--(E)
* |
* (A)-+-(C)
* |
* | +-(F)
* | |
* +-(D)-+
* |
* +-(G)
*
*
* A {@link FlatTreeModel} of that base model will look like this:
*
*
* +-(E)
* |
* (A)-+-(C)
* |
* +-(F)
* |
* +-(G)
*
*
* @author René Link {@literal }
*/
public class FlatTreeModel implements TreeModel {
private TreeModel baseModel;
public FlatTreeModel(TreeModel baseModel) {
this.baseModel = baseModel;
}
@Override
public Stream extends T> getChildren(T parent) {
if (baseModel.hasChildren(parent)) {
List