mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Tree add 类型校验
This commit is contained in:
parent
0fc10205a0
commit
b69ae38829
@ -10,6 +10,7 @@
|
|||||||
* 【core 】 DateUtil.parseUTC支持只有时分的格式(issue#I5M6DP@Gitee)
|
* 【core 】 DateUtil.parseUTC支持只有时分的格式(issue#I5M6DP@Gitee)
|
||||||
* 【core 】 NumberUtil.parseInt忽略科学计数法(issue#I5M55F@Gitee)
|
* 【core 】 NumberUtil.parseInt忽略科学计数法(issue#I5M55F@Gitee)
|
||||||
* 【core 】 IterUtil.getFirst优化(pr#753@Gitee)
|
* 【core 】 IterUtil.getFirst优化(pr#753@Gitee)
|
||||||
|
* 【core 】 增加Tree add 类型校验(pr#2542@Github)
|
||||||
*
|
*
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
* 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee)
|
||||||
|
@ -158,17 +158,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public <T> TreeBuilder<E> append(List<T> list, NodeParser<T, E> nodeParser) {
|
public <T> TreeBuilder<E> append(List<T> list, NodeParser<T, E> nodeParser) {
|
||||||
checkBuilt();
|
return append(list, null, nodeParser);
|
||||||
|
|
||||||
final TreeNodeConfig config = this.root.getConfig();
|
|
||||||
final Map<E, Tree<E>> map = new LinkedHashMap<>(list.size(), 1);
|
|
||||||
Tree<E> node;
|
|
||||||
for (T t : list) {
|
|
||||||
node = new Tree<>(config);
|
|
||||||
nodeParser.parse(t, node);
|
|
||||||
map.put(node.getId(), node);
|
|
||||||
}
|
|
||||||
return append(map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,6 +168,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
|||||||
* @param <T> Bean类型
|
* @param <T> Bean类型
|
||||||
* @param nodeParser 节点转换器,用于定义一个Bean如何转换为Tree节点
|
* @param nodeParser 节点转换器,用于定义一个Bean如何转换为Tree节点
|
||||||
* @return this
|
* @return this
|
||||||
|
* @since 5.8.6
|
||||||
*/
|
*/
|
||||||
public <T> TreeBuilder<E> append(List<T> list, E rootId, NodeParser<T, E> nodeParser) {
|
public <T> TreeBuilder<E> append(List<T> list, E rootId, NodeParser<T, E> nodeParser) {
|
||||||
checkBuilt();
|
checkBuilt();
|
||||||
@ -188,7 +179,7 @@ public class TreeBuilder<E> implements Builder<Tree<E>> {
|
|||||||
for (T t : list) {
|
for (T t : list) {
|
||||||
node = new Tree<>(config);
|
node = new Tree<>(config);
|
||||||
nodeParser.parse(t, node);
|
nodeParser.parse(t, node);
|
||||||
if (!rootId.getClass().equals(node.getId().getClass())) {
|
if (null != rootId && false == rootId.getClass().equals(node.getId().getClass())) {
|
||||||
throw new IllegalArgumentException("rootId type is node.getId().getClass()!");
|
throw new IllegalArgumentException("rootId type is node.getId().getClass()!");
|
||||||
}
|
}
|
||||||
map.put(node.getId(), node);
|
map.put(node.getId(), node);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.hutool.core.lang.tree;
|
package cn.hutool.core.lang.tree;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -56,36 +57,10 @@ public class Issues2538Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
public static class Test {
|
public static class Test {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private long parentId;
|
private long parentId;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getParentId() {
|
|
||||||
return parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentId(long parentId) {
|
|
||||||
this.parentId = parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user