package com.yeejoin.amos.fas.business.util;

import org.typroject.tyboot.core.foundation.utils.TreeNode;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <h1><h1>
 *
 * @author tiantao
 * @date 2020/12/7 14:23
 */
public class TreeUtil {

    public static<T extends TreeNode>  List<T> getAllChildren(Collection<T> trees) {
        List<T> childrenNodes = new ArrayList<>();
        if (!ValidationUtil.isEmpty(trees)) {
            trees.forEach(node->{
                childrenNodes.add(node);
                if (!ValidationUtil.isEmpty(node.getChildren())) {
                    childrenNodes.addAll(getAllChildren(node.getChildren()));
                }
            });
        }
        return childrenNodes;
    }
}
