Visitor pattern, recursively traverse the tree node

interface TreeVisitor {
    /**
     * 访问函数
     *
     * @param t 访问对象(树节点)
     */
    void visit(ItemVO t);
}

    /**
     * 访问者模式,递归遍历树节点
     *
     * @param t       树节点
     * @param visitor 访问者
     */
    private static void visitTree(ItemVO t, TreeVisitor visitor) {
        visitor.visit(t);
        if (null != t.children) {
            for (ItemVO child : t.children) {
                visitTree(child, visitor);
            }
        }
    }




Kotlin developer community

1233356-4cc10b922a41aa80

Related Topics domestic first Kotlin developer community public numbers, the main share exchange Kotlin programming language, Spring Boot, Android, React.js / Node.js, functional programming, programming ideas and so on.

The more hustle and bustle of the world, the more you need quiet to think.

Released 1571 original articles · won praise 627 · views 610 000 +

Guess you like

Origin blog.csdn.net/universsky2015/article/details/104193271