import lombok.Data; import lombok.experimental.Accessors; import java.util.List; /** * @author :zhangyang * @version :1.0 * @description: * @date :Created in 2020/6/10 9:54 * @modified By: */ @Data @Accessors(chain = true) public class DemoClass { private String id; private String name; private String pid; private List<DemoClass> children; }
import com.google.common.collect.Lists; import com.google.common.collect.Maps; import lombok.AllArgsConstructor; import java.util.List; import java.util.Map; /** * @author :zhangyang * @version :1.0 * @description:递归 * @date :Created in 2020/6/10 11:11 * @modified By: */ @AllArgsConstructor public class DiGui { /** * 父节点 */ private List<DemoClass> root; /** * 所有节点(或不包含父节点) */ private List<DemoClass> body; public List<DemoClass> returnList() { if (body != null && !body.isEmpty()) { Map<String, String> map = Maps.newHashMapWithExpectedSize(body.size()); root.forEach(entity -> getChildren(entity, map)); return root; } return null; } public void getChildren(DemoClass demoClass, Map<String, String> map) { List<DemoClass> children = Lists.newArrayList(); body.stream() .filter(entity -> !map.containsKey(entity.getId())) .filter(entity -> entity.getPid().equals(demoClass.getId())) .forEach(entity -> { map.put(entity.getId(), entity.getPid()); getChildren(entity, map); children.add(entity); }); demoClass.setChildren(children); } }
import com.alibaba.fastjson.JSONObject; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import java.util.List; /** * @author :zhangyang * @version :1.0 * @description: * @date :Created in 2020/6/10 9:53 * @modified By: */ @Slf4j public class Demo { public static void main(String[] args) { List<DemoClass> root = Lists.newArrayList( new DemoClass().setId("1").setName("1").setPid("0"), new DemoClass().setId("2").setName("2").setPid("0"), new DemoClass().setId("3").setName("3").setPid("0"), new DemoClass().setId("4").setName("4").setPid("0") ); List<DemoClass> body = Lists.newArrayList( new DemoClass().setId("1").setName("1").setPid("0"), new DemoClass().setId("2").setName("2").setPid("0"), new DemoClass().setId("3").setName("3").setPid("0"), new DemoClass().setId("4").setName("4").setPid("0"), new DemoClass().setId("11").setName("1>1").setPid("1"), new DemoClass().setId("12").setName("1>2").setPid("1"), new DemoClass().setId("21").setName("2>1").setPid("2"), new DemoClass().setId("31").setName("3>1").setPid("3") ); DiGui digui = new DiGui(root,body); List<DemoClass> list = digui.returnList(); log.info("JSON"+JSONObject.toJSON(list)); } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算