### Question:
TreeUtil { public static <T extends INode> List<T> merge(List<T> items) { ForestNodeManager<T> forestNodeManager = new ForestNodeManager<>(items); items.forEach(forestNode -> { if (forestNode.getParentId() != 0) { INode node = forestNodeManager.getTreeNodeAT(forestNode.getParentId()); if (node != null) { node.getChildren().add(forestNode); } else { forestNodeManager.addParentId(forestNode.getId()); } } }); return forestNodeManager.getRoot(); }  static List<T> build(List<T> treeNodes, Object root); static List<T> buildByRecursive(List<T> treeNodes, Object root); static T findChildren(T treeNode, List<T> treeNodes); static List<T> merge(List<T> items);  }### Answer:
@Test public void testMerge() { List<ForestNode> list = new ArrayList<>(); list.add(new ForestNode(1, 0, "1")); list.add(new ForestNode(2, 0, "2")); list.add(new ForestNode(3, 1, "3")); list.add(new ForestNode(4, 2, "4")); list.add(new ForestNode(5, 3, "5")); list.add(new ForestNode(6, 4, "6")); list.add(new ForestNode(7, 3, "7")); list.add(new ForestNode(8, 5, "8")); list.add(new ForestNode(9, 6, "9")); list.add(new ForestNode(10, 9, "10")); List<ForestNode> tns = TreeUtil.merge(list); tns.forEach(node -> System.out.println(JSONUtil.toJsonStr(node))); System.out.println(JSONUtil.toJsonStr(tns)); }