PK - 主键类型public interface TreeSupportEntity<PK> extends Entity
| 限定符和类型 | 接口和说明 |
|---|---|
static interface |
TreeSupportEntity.TreeHelper<T,PK>
树结构Helper
|
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends TreeSupportEntity<PK>,PK> |
expandTree2List(T parent,
IDGenerator<PK> idGenerator) |
static <T extends TreeSupportEntity<PK>,PK> |
expandTree2List(T parent,
List<T> target,
IDGenerator<PK> idGenerator) |
static <T extends TreeSupportEntity<PK>,PK> |
expandTree2List(T root,
List<T> target,
IDGenerator<PK> idGenerator,
java.util.function.BiConsumer<T,List<T>> childConsumer)
将树形结构转为列表结构,并填充对应的数据。
|
static <T extends TreeSupportEntity> |
forEach(Collection<T> list,
java.util.function.Consumer<T> consumer) |
<T extends TreeSupportEntity<PK>> |
getChildren()
获取所有子节点,默认情况下此字段只会返回null.可以使用
list2tree(Collection, BiConsumer)将
列表结构转为树形结构 |
PK |
getId()
获取主键
|
Integer |
getLevel()
获取节点层级
|
PK |
getParentId()
获取上级ID
|
static String |
getParentPath(String path)
根据path获取父节点的path
|
String |
getPath()
获取树路径,树路径表示当前节点所在位置
格式通常为: aBcD-EfgH-iJkl,以-分割,一个分割表示一级.
|
static <N extends TreeSupportEntity<PK>,PK> |
list2tree(Collection<N> dataList,
java.util.function.BiConsumer<N,List<N>> childConsumer)
集合转为树形结构,返回根节点集合
|
static <N extends TreeSupportEntity<PK>,PK> |
list2tree(Collection<N> dataList,
java.util.function.BiConsumer<N,List<N>> childConsumer,
java.util.function.Function<TreeSupportEntity.TreeHelper<N,PK>,java.util.function.Predicate<N>> predicateFunction)
列表结构转为树结构,并返回根节点集合
|
static <N extends TreeSupportEntity<PK>,PK> |
list2tree(Collection<N> dataList,
java.util.function.BiConsumer<N,List<N>> childConsumer,
java.util.function.Predicate<N> rootNodePredicate) |
void |
setId(PK id)
设置主键
|
void |
setLevel(Integer level)
设置节点层级
|
void |
setParentId(PK parentId)
设置上级节点ID
|
void |
setPath(String path)
设置路径,此值通常不需要手动设置,在进行保存时,由service自动进行分配.
|
default void |
tryValidate(Class<?>... groups)
使用jsr303对当前实体类进行验证,如果未通过验证则会抛出
ValidationException异常 |
copyFrom, copyTo, copyTo, tryValidate, tryValidatePK getId()
void setId(PK id)
id - IDString getPath()
void setPath(String path)
path - 路径expandTree2List(TreeSupportEntity, IDGenerator)PK getParentId()
void setParentId(PK parentId)
parentId - Integer getLevel()
void setLevel(Integer level)
<T extends TreeSupportEntity<PK>> List<T> getChildren()
list2tree(Collection, BiConsumer)将
列表结构转为树形结构T - 当前实体类型default void tryValidate(Class<?>... groups)
EntityValidationException异常tryValidate 在接口中 Entitygroups - 分组ValidationExceptionstatic <T extends TreeSupportEntity> void forEach(Collection<T> list, java.util.function.Consumer<T> consumer)
static <T extends TreeSupportEntity<PK>,PK> List<T> expandTree2List(T parent, IDGenerator<PK> idGenerator)
static <T extends TreeSupportEntity<PK>,PK> void expandTree2List(T parent, List<T> target, IDGenerator<PK> idGenerator)
static <T extends TreeSupportEntity<PK>,PK> void expandTree2List(T root, List<T> target, IDGenerator<PK> idGenerator, java.util.function.BiConsumer<T,List<T>> childConsumer)
T - 继承TreeSupportEntity的类型PK - 主键类型root - 树结构的根节点target - 目标集合,转换后的数据将直接添加(List.add(Object))到这个集合.idGenerator - ID生成策略static <N extends TreeSupportEntity<PK>,PK> List<N> list2tree(Collection<N> dataList, java.util.function.BiConsumer<N,List<N>> childConsumer)
N - 树节点类型PK - 主键类型dataList - 需要转换的集合childConsumer - 设置子节点回调static <N extends TreeSupportEntity<PK>,PK> List<N> list2tree(Collection<N> dataList, java.util.function.BiConsumer<N,List<N>> childConsumer, java.util.function.Predicate<N> rootNodePredicate)
static <N extends TreeSupportEntity<PK>,PK> List<N> list2tree(Collection<N> dataList, java.util.function.BiConsumer<N,List<N>> childConsumer, java.util.function.Function<TreeSupportEntity.TreeHelper<N,PK>,java.util.function.Predicate<N>> predicateFunction)
N - 元素类型PK - 主键类型dataList - 数据集合childConsumer - 子节点消费接口,用于设置子节点predicateFunction - 根节点判断函数,传入helper,获取一个判断是否为跟节点的函数Copyright © 2016–2023. All rights reserved.