io.github.jinghui70.rainbow.utils.TreeUtils Maven / Gradle / Ivy
package io.github.jinghui70.rainbow.utils;
import cn.hutool.core.collection.CollUtil;
import java.util.List;
import java.util.function.Consumer;
public class TreeUtils {
public static > void traverse(T treeNode, Consumer consumer) {
if (treeNode == null) return;
consumer.accept(treeNode);
traverse(treeNode.getChildren(), consumer);
}
public static > void traverse(List tree, Consumer consumer) {
if (CollUtil.isEmpty(tree)) return;
for (T node : tree) {
traverse(node, consumer);
}
}
}