
package cn.palmte.work.pojo;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class PermissionNode {
    private static final Logger logger = LoggerFactory.getLogger(PermissionNode.class);

    private int                  id; //id
    private int                  parentId; // 父id
    private int                  level;// 层级
    private String                name;//名称
    private boolean              hasLeafNode      = false; // 是否有叶子子代
    private boolean              isLeafNode       = false; //是否是叶子节点
    private boolean              selected         = false; // 是否已选中
    private List<PermissionNode> subNodes; // 子代集合

    public int getId(){
        return id;
    }

    public void setId(int id){
        this.id = id;
    }

    public String getName(){
        return name;
    }

    public void setName(String name){
        this.name = name;
    }

    public boolean isLeafNode(){
        return isLeafNode;
    }

    public void setLeafNode(boolean isLeafNode){
        this.isLeafNode = isLeafNode;
    }

    public List<PermissionNode> getSubNodes(){
        return subNodes;
    }

    public void addSubNode(PermissionNode node){
        if(subNodes == null){
            subNodes = new ArrayList<PermissionNode>();
        }
        if(node.isLeafNode){
            hasLeafNode = true;
        }
        subNodes.add(node);
    }

    public int getParentId(){
        return parentId;
    }

    public void setParentId(int parentId){
        this.parentId = parentId;
    }

    public void setSubNodes(List<PermissionNode> subNodes){
        this.subNodes = subNodes;
    }

    public boolean isHasLeafNode(){
        return hasLeafNode;
    }

    public void setHasLeafNode(boolean hasLeafNode){
        this.hasLeafNode = hasLeafNode;
    }

    public int getLevel(){
        return level;
    }

    public void setLevel(int level){
        this.level = level;
    }

    public boolean isSelected(){
        return selected;
    }

    public void setSelected(boolean selected){
        this.selected = selected;
    }

    @Override
    public String toString(){
        return name + "[" + id + ",pId:" + parentId + ",checked:" + selected + ",hasLeafNode:" + hasLeafNode + "]";
    }



}
