All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.wzc789376152.vo.TreeVo Maven / Gradle / Ivy

The newest version!
package com.github.wzc789376152.vo;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;



public class TreeVo {
    private Serializable id;
    private Serializable parentId;
    private Collection childList;

    public static > List getTreeModel(Collection treeModels) {
        return findParent(treeModels);
    }

    public static > List findChild(Serializable parentId, Collection treeModels) {
        return treeModels.stream().filter(i -> i.getParentId() != null && i.getParentId().equals(parentId)).peek(i -> i.setChildList(findChild(i.getId(), treeModels))).collect(Collectors.toList());
    }

    private static > List findParent(Collection treeModels) {
        return treeModels.stream().filter(i -> i.getParentId() == null || treeModels.stream().noneMatch(j -> j.getId().equals(i.getParentId()))).peek(i -> i.setChildList(findChild(i.getId(), treeModels))).collect(Collectors.toList());
    }


    public Serializable getParentId() {
        return parentId;
    }

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

    public Serializable getId() {
        return id;
    }

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

    public void setChildList(Collection childList) {
        this.childList = childList;
    }

    public Collection getChildList() {
        return childList;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy