-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
25 changed files
with
532 additions
and
213 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
11 changes: 4 additions & 7 deletions
11
...rule/api/vistor/BreadthTraversalMode.java → ...astructure/tree/BreadthTraversalMode.java
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
62 changes: 62 additions & 0 deletions
62
uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultElement.java
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cc.allio.uno.core.datastructure.tree; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* 默认树结点 | ||
* | ||
* @author j.x | ||
* @date 2023/11/9 11:36 | ||
* @since 1.1.5 | ||
*/ | ||
@Getter | ||
public class DefaultElement extends TraversalElement { | ||
|
||
private final Serializable id; | ||
@Setter | ||
private int depth; | ||
|
||
@Setter | ||
private Element parent; | ||
|
||
private final List<Element> children; | ||
|
||
public DefaultElement(@NonNull Serializable id) { | ||
this.id = id; | ||
this.children = Lists.newArrayList(); | ||
} | ||
|
||
public DefaultElement(@NonNull Serializable id, int depth) { | ||
this.id = id; | ||
this.depth = depth; | ||
this.children = Lists.newArrayList(); | ||
} | ||
|
||
@Override | ||
public boolean isLeaf() { | ||
return children.isEmpty(); | ||
} | ||
|
||
@Override | ||
public <T extends Element> void setChildren(List<T> children) { | ||
clearChildren(); | ||
this.children.addAll(children); | ||
} | ||
|
||
@Override | ||
public void addChildren(Element element) { | ||
children.add(element); | ||
} | ||
|
||
@Override | ||
public void clearChildren() { | ||
children.clear(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DefaultExpand.java
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cc.allio.uno.core.datastructure.tree; | ||
|
||
import java.io.Serializable; | ||
|
||
public record DefaultExpand(Serializable id, Serializable parentId) implements Expand { | ||
@Override | ||
public Serializable getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public Serializable getParentId() { | ||
return parentId; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Element.java
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package cc.allio.uno.core.datastructure.tree; | ||
|
||
import cc.allio.uno.core.StringPool; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* 节点类型分为两种: | ||
* <ul> | ||
* <li>group 节点</li> | ||
* <li>attr 节点</li> | ||
* </ul> | ||
* | ||
* @author jiangwei | ||
* @date 2023/4/26 11:31 | ||
* @since 1.1.4 | ||
*/ | ||
public interface Element extends Serializable { | ||
|
||
Element ROOT_SENTINEL = new DefaultElement(-1, -1); | ||
|
||
/** | ||
* 定义根节点 | ||
*/ | ||
int ROOT_NODE = 0; | ||
|
||
/** | ||
* 获取树的标识 | ||
*/ | ||
Serializable getId(); | ||
|
||
/** | ||
* 获取节点所在的深度 | ||
* | ||
* @return level | ||
*/ | ||
int getDepth(); | ||
|
||
/** | ||
* 设置树的层级 | ||
*/ | ||
void setDepth(int depth); | ||
|
||
/** | ||
* 获取当前树的路径 | ||
* | ||
* @return a.b.c以'.'来切分路径标识 | ||
*/ | ||
default String getPath() { | ||
return getParent() != null ? getParent().getPath() + StringPool.ORIGIN_DOT + getId() : String.valueOf(getId()); | ||
} | ||
|
||
/** | ||
* 获取父节点 | ||
* | ||
* @return Element | ||
*/ | ||
<T extends Element> T getParent(); | ||
|
||
/** | ||
* 设置父节点 | ||
* | ||
* @param parent parent node | ||
*/ | ||
<T extends Element> void setParent(T parent); | ||
|
||
/** | ||
* 是否为根节点 | ||
* | ||
* @return true 是 false 否 | ||
*/ | ||
default boolean isRoot() { | ||
return getDepth() == ROOT_NODE; | ||
} | ||
|
||
/** | ||
* 是否为叶子节点 | ||
* | ||
* @return true 是 false 否 | ||
*/ | ||
boolean isLeaf(); | ||
|
||
/** | ||
* 获取子节点 | ||
* | ||
* @return element list | ||
*/ | ||
<T extends Element> List<T> getChildren(); | ||
|
||
/** | ||
* 添加子结点 | ||
*/ | ||
<T extends Element> void addChildren(T element); | ||
|
||
/** | ||
* 覆盖并设置子结点 | ||
* | ||
* @param children children | ||
*/ | ||
<T extends Element> void setChildren(List<T> children); | ||
|
||
/** | ||
* 清除children数据 | ||
*/ | ||
void clearChildren(); | ||
|
||
/** | ||
* 访问器模式访问每一个节点。默认实现为深度优先原则 | ||
* | ||
* @param visitor visitor | ||
*/ | ||
default void accept(Visitor visitor) { | ||
accept(visitor, Traversal.NONE); | ||
} | ||
|
||
/** | ||
* 访问器模式访问每一个节点。默认实现为深度优先原则 | ||
* | ||
* @param visitor visitor | ||
* @param traversal 遍历原则 | ||
*/ | ||
void accept(Visitor visitor, Traversal traversal); | ||
} |
23 changes: 23 additions & 0 deletions
23
uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Expand.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cc.allio.uno.core.datastructure.tree; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 树平展结点 | ||
* | ||
* @author j.x | ||
* @date 2023/11/9 11:32 | ||
* @since 1.1.5 | ||
*/ | ||
public interface Expand { | ||
|
||
/** | ||
* 获取当前结点的标识 | ||
*/ | ||
Serializable getId(); | ||
|
||
/** | ||
* 获取父节点标识 | ||
*/ | ||
Serializable getParentId(); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
.../allio/uno/rule/api/vistor/Traversal.java → ...no/core/datastructure/tree/Traversal.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cc.allio.uno.rule.api.vistor; | ||
package cc.allio.uno.core.datastructure.tree; | ||
|
||
/** | ||
* 规则树遍历方式 | ||
|
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
2 changes: 1 addition & 1 deletion
2
...io/uno/rule/api/vistor/TraversalMode.java → ...ore/datastructure/tree/TraversalMode.java
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
Oops, something went wrong.