@@ -0,0 +1,1643 @@
+package org.onetwo.common.tree;%0A/**%0A * @author weishao zeng%0A * %3Cbr/%3E%0A */%0A%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0A%0Aimport org.junit.Test;%0A%0Aimport com.google.common.collect.Lists;%0A%0Apublic class TreeBuilderTest %7B%0A%09%0A%09@Test%0A%09public void testBuildTree() %7B%0A%09%09TreeNodeDataTest data1 = new TreeNodeDataTest(1L, null, %22node1%22);%0A%09%09TreeNodeDataTest data2 = new TreeNodeDataTest(2L, 1L, %22node2%22);%0A%09%09TreeNodeDataTest data3 = new TreeNodeDataTest(3L, 2L, %22node3%22);%0A%09%09TreeNodeDataTest data4 = new TreeNodeDataTest(4L, 1L, %22node4%22);%0A%09%09TreeNodeDataTest data5 = new TreeNodeDataTest(5L, 4L, %22node5%22);%0A%09%09List%3CTreeNodeDataTest%3E datas = Lists.newArrayList(data1, data2, data3, data4, data5);%0A%09%09%0A%09%09List%3CDefaultTreeModel%3E models = datas.stream().map(d-%3E%7B%0A%09%09%09return new DefaultTreeModel(d.getId(), d.getName(), d.getParentId());%0A%09%09%7D).collect(Collectors.toList());%0A%09%09TreeBuilder%3CDefaultTreeModel%3E treeBuilder = new TreeBuilder%3C%3E(models);%0A%09%09List%3CDefaultTreeModel%3E roots = treeBuilder.buidTree();%0A%09%09System.out.println(%22roots: %5Cn%22 + roots.get(0));%0A%09%7D%0A%09%0A%09public static class TreeNodeDataTest %7B%0A%09%09private Long id;%0A%09%09private Long parentId;%0A%09%09private String name;%0A%09%09%0A%09%09public TreeNodeDataTest(Long id, Long parentId, String name) %7B%0A%09%09%09super();%0A%09%09%09this.id = id;%0A%09%09%09this.parentId = parentId;%0A%09%09%09this.name = name;%0A%09%09%7D%0A%09%09public Long getId() %7B%0A%09%09%09return id;%0A%09%09%7D%0A%09%09public void setId(Long id) %7B%0A%09%09%09this.id = id;%0A%09%09%7D%0A%09%09public Long getParentId() %7B%0A%09%09%09return parentId;%0A%09%09%7D%0A%09%09public void setParentId(Long parentId) %7B%0A%09%09%09this.parentId = parentId;%0A%09%09%7D%0A%09%09public String getName() %7B%0A%09%09%09return name;%0A%09%09%7D%0A%09%09public void setName(String name) %7B%0A%09%09%09this.name = name;%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A%0A

add treebuilder test