概述
@Override
public List<BaseZTree> getTemplateData(){
List<BaseZTree> queryList = getDirectory("-1",false);
List<BaseZTree> parentList = new ArrayList<>();
for (BaseZTree baseZTree : queryList) {
if (StringUtils.isBlank(baseZTree.getpId())) {
parentList.add(baseZTree);
}
}
recursionChildren(parentList, queryList);
return parentList;
}
private void recursionChildren(List<BaseZTree> parentList, List<BaseZTree> allList) {
for (BaseZTree parentBaseZTree : parentList) {
List<BaseZTree> childrenList = new ArrayList<>();
for (BaseZTree baseZTree : allList) {
if (baseZTree.getpId().equals(parentBaseZTree.getId())) {
childrenList.add(baseZTree);
}
}
if (ObjectUtil.isNotNull(childrenList)) {
parentBaseZTree.setChildren(childrenList);
recursionChildren(childrenList, allList);
}
}
}
**
* ztree 结构 实体类
* @author mbh
* @date 2018/10/16 15:40
*/
public class BaseZTree {
private String id;
private String pId;
private String name;
private String text;
private String nodeType;
private boolean isParent;
private boolean open;
private List<BaseZTree> children = new ArrayList<>();
private int position;
public BaseZTree() {
}
public BaseZTree(String id, String name) {
this.id = id;
this.name = name;
}
/**
* 节点其他属性,传递其他属性zTree控件需要这样配置
*/
private Map<String, String> attributes = new HashMap<String, String>();
//private List<TPln6Flow> children = new ArrayList<TPln6Flow>();
private String icon;
private boolean nocheck;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// public List<TPln6Flow> getChildren() {
// return children;
// }
//
// public void setChildren(List<TPln6Flow> children) {
// this.children = children;
// }
public List<BaseZTree> getChildren() {
return children;
}
public void setChildren(List<BaseZTree> children) {
this.children = children;
}
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
public String getNodeType() {
return nodeType;
}
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
}
public boolean getIsParent() {
return isParent;
}
public void setIsParent(boolean isparent) {
isParent = isparent;
}
public boolean getOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getpId() {
return pId;
}
public void setpId(String pId) {
this.pId = pId;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public boolean isNocheck() {
return nocheck;
}
public void setNocheck(boolean nocheck) {
this.nocheck = nocheck;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public void addChildren(BaseZTree baseZTree) {
List<BaseZTree> nodes = this.getChildren();
if (nodes == null) {
List<BaseZTree> list = new ArrayList<>();
list.add(baseZTree);
this.setChildren(list);
}else{
nodes.add(baseZTree);
}
}
}
最后
以上就是开朗龙猫为你收集整理的java Tree结构数据的全部内容,希望文章能够帮你解决java Tree结构数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复