-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d7284c
commit 6f55581
Showing
4 changed files
with
16 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import cn.hutool.core.collection.CollUtil; | ||
import cn.hutool.core.util.ObjectUtil; | ||
import com.google.common.collect.Maps; | ||
import com.jmsoftware.maf.springcloudstarter.annotation.TreeElement; | ||
|
||
import java.beans.BeanInfo; | ||
|
@@ -21,6 +22,7 @@ | |
* | ||
* @author Johnny Miller (锺俊), email: [email protected], date: 5/28/2021 4:27 PM | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class TreeUtil { | ||
/** | ||
* Convert List to Tree | ||
|
@@ -37,16 +39,14 @@ public static <T> List<T> listToTree(List<T> list, String rootNode) throws Illeg | |
IntrospectionException, InvocationTargetException { | ||
// Root node collection | ||
List<T> rootList = new ArrayList<>(); | ||
HashMap<Object, List<T>> parentIdToTree = CollUtil.newHashMap(list.size()); | ||
HashMap<Object, List<T>> parentIdToTree = Maps.newHashMap(); | ||
for (final T t : list) { | ||
Object value = getValue(t, TreeElementType.PARENT_ID); | ||
if (ObjectUtil.isNotNull(value)) { | ||
if (ObjectUtil.isNotNull(parentIdToTree.get(value))) { | ||
parentIdToTree.get(value).add(t); | ||
} else { | ||
parentIdToTree.put(value, new ArrayList<>() {{ | ||
this.add(t); | ||
}}); | ||
parentIdToTree.put(value, CollUtil.newArrayList(t)); | ||
} | ||
if (rootNode.equals(value)) { | ||
rootList.add(t); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters