首页>代码>SpringBoot爬取html生成CHM帮助文档>/springboot-chm/src/main/java/com/simon/springbootchm/vo/ContentsNode.java
package com.simon.springbootchm.vo;

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

/**
 * 用于生成chm工程文件节点的 node类
 *
 * @author Simon
 */
public class ContentsNode {
    private boolean isHeading;
    private String title;
    private String path;
    private ArrayList<ContentsNode> children;

    ContentsNode(String title, String path, boolean isHeading) {
        this.title = title;
        this.path = path;
        this.isHeading = isHeading;
    }

    public static ContentsNode newHeading(String title) {
        return newHeading(title, null);
    }

    public static ContentsNode newHeading(String title, String path) {
        ContentsNode contentsNode = new ContentsNode(title, path, true);
        contentsNode.setChildren(new ArrayList<ContentsNode>());
        return contentsNode;
    }

    public static ContentsNode newTopic(String title, String path) {
        return new ContentsNode(title, path, false);
    }

    public boolean addChild(ContentsNode node) {
        if (isHeading && children != null)
            return children.add(node);
        else
            return false;
    }

    public static ArrayList<ContentsNode> makeTreeData(List<ContentsNode> nodes) {
        ArrayList<ContentsNode> tree = new ArrayList<>();
        ContentsNode node = null;
        for (ContentsNode child : nodes) {
            if (child.isHeading()) {
                if (node != null) tree.add(node);
                node = child;
                node.children = new ArrayList<>();
            } else {
                if (node != null) node.addChild(child);
                else tree.add(child);
            }
        }
        if (node != null) tree.add(node);
        return tree;
    }

    public boolean isHeading() {
        return isHeading;
    }

    public void setHeading(boolean heading) {
        isHeading = heading;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public ArrayList<ContentsNode> getChildren() {
        return children;
    }

    public void setChildren(ArrayList<ContentsNode> children) {
        this.children = children;
    }
}
最近下载更多
139465  LV12 2023年3月29日
crosa_Don  LV18 2023年3月2日
最代码官方  LV168 2023年2月19日
最近浏览更多
3334004690  LV11 3月8日
茶茶茶百道qq 2023年9月20日
暂无贡献等级
多加两块钱  LV4 2023年6月12日
skook7  LV2 2023年6月1日
szf123  LV12 2023年5月30日
duanzhouyang  LV10 2023年5月12日
Pro_Guoli 2023年5月12日
暂无贡献等级
fewfsdaf  LV4 2023年4月18日
做你的景天  LV7 2023年4月12日
master_guo  LV7 2023年4月12日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友