diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ac1de802..61fdb88e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * 【core 】 增加IterableIter、ComputeIter * 【core 】 CsvConfig增加disableComment方法(issue#1842@Github) * 【core 】 DateTime构造和DateUtil.parse可选是否宽松模式(issue#1849@Github) +* 【core 】 TreeBuilder增加部分根节点set方法(issue#1848@Github) ### 🐞Bug修复 * 【http 】 修复HttpCookie设置cookies的方法,不符合RFC6265规范问题(pr#418@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/lang/tree/TreeBuilder.java b/hutool-core/src/main/java/cn/hutool/core/lang/tree/TreeBuilder.java index f398097ea..6b4103c7d 100644 --- a/hutool-core/src/main/java/cn/hutool/core/lang/tree/TreeBuilder.java +++ b/hutool-core/src/main/java/cn/hutool/core/lang/tree/TreeBuilder.java @@ -59,6 +59,67 @@ public class TreeBuilder implements Builder> { this.idTreeMap = new HashMap<>(); } + /** + * 设置ID + * + * @param id ID + * @return this + * @since 5.7.14 + */ + public TreeBuilder setId(E id) { + this.root.setId(id); + return this; + } + + /** + * 设置父节点ID + * + * @param parentId 父节点ID + * @return this + * @since 5.7.14 + */ + public TreeBuilder setParentId(E parentId) { + this.root.setParentId(parentId); + return this; + } + + /** + * 设置节点标签名称 + * + * @param name 节点标签名称 + * @return this + * @since 5.7.14 + */ + public TreeBuilder setName(CharSequence name) { + this.root.setName(name); + return this; + } + + /** + * 设置权重 + * + * @param weight 权重 + * @return this + * @since 5.7.14 + */ + public TreeBuilder setWeight(Comparable weight) { + this.root.setWeight(weight); + return this; + } + + /** + * 扩展属性 + * + * @param key 键 + * @param value 扩展值 + * @since 5.7.14 + */ + public TreeBuilder putExtra(String key, Object value) { + Assert.notEmpty(key, "Key must be not empty !"); + this.root.put(key, value); + return this; + } + /** * 增加节点列表,增加的节点是不带子节点的 *