Parcourir la source

enhancement #I6LWYM 深层次优化Condition维度的代码

everywhere.z il y a 2 ans
Parent
commit
986dcb7cdb

+ 3 - 1
liteflow-core/src/main/java/com/yomahub/liteflow/enums/ConditionTypeEnum.java

@@ -16,7 +16,9 @@ public enum ConditionTypeEnum {
 
     TYPE_WHILE("while", "while"),
 
-    TYPE_ITERATOR("iterator", "iterator")
+    TYPE_ITERATOR("iterator", "iterator"),
+
+    TYPE_CATCH("catch", "catch")
     ;
     private String type;
     private String name;

+ 34 - 0
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ConditionKey.java

@@ -0,0 +1,34 @@
+package com.yomahub.liteflow.flow.element.condition;
+
+public interface ConditionKey {
+
+    String DEFAULT_KEY = "DEFAULT_KEY";
+
+    String FOR_KEY = "FOR_KEY";
+
+    String IF_KEY = "IF_KEY";
+
+    String IF_TRUE_CASE_KEY = "IF_TRUE_CASE_KEY";
+
+    String IF_FALSE_CASE_KEY = "IF_FALSE_CASE_KEY";
+
+    String ITERATOR_KEY = "ITERATOR_KEY";
+
+    String DO_KEY = "DO_KEY";
+
+    String BREAK_KEY = "BREAK_KEY";
+
+    String SWITCH_KEY = "SWITCH_KEY";
+
+    String SWITCH_TARGET_KEY = "SWITCH_TARGET_KEY";
+
+    String SWITCH_DEFAULT_KEY = "SWITCH_DEFAULT_KEY";
+
+    String PRE_KEY = "PRE_KEY";
+
+    String FINALLY_KEY = "FINALLY_KEY";
+
+    String WHILE_KEY = "WHILE_KEY";
+
+    String CATCH_KEY = "CATCH_KEY";
+}

+ 2 - 4
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java

@@ -18,8 +18,6 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
  */
 public class ForCondition extends LoopCondition{
 
-    private final String FOR_ITEM = "FOR_ITEM";
-
     @Override
     public void execute(Integer slotIndex) throws Exception {
         Slot slot = DataBus.getSlot(slotIndex);
@@ -75,10 +73,10 @@ public class ForCondition extends LoopCondition{
     }
 
     public Node getForNode() {
-        return (Node) this.getExecutableOne(FOR_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.FOR_KEY);
     }
 
     public void setForNode(Node forNode) {
-        this.addExecutable(FOR_ITEM, forNode);
+        this.addExecutable(ConditionKey.FOR_KEY, forNode);
     }
 }

+ 6 - 12
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IfCondition.java

@@ -20,12 +20,6 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
  */
 public class IfCondition extends Condition {
 
-    private final String IF_ITEM = "IF_ITEM";
-
-    private final String TRUE_CASE_GROUP = "TRUE_CASE";
-
-    private final String FALSE_CASE_GROUP = "FALSE_CASE";
-
     @Override
     public void execute(Integer slotIndex) throws Exception {
         if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())){
@@ -88,26 +82,26 @@ public class IfCondition extends Condition {
     }
 
     public Executable getTrueCaseExecutableItem() {
-        return this.getExecutableOne(TRUE_CASE_GROUP);
+        return this.getExecutableOne(ConditionKey.IF_TRUE_CASE_KEY);
     }
 
     public void setTrueCaseExecutableItem(Executable trueCaseExecutableItem) {
-        this.addExecutable(TRUE_CASE_GROUP, trueCaseExecutableItem);
+        this.addExecutable(ConditionKey.IF_TRUE_CASE_KEY, trueCaseExecutableItem);
     }
 
     public Executable getFalseCaseExecutableItem() {
-        return this.getExecutableOne(FALSE_CASE_GROUP);
+        return this.getExecutableOne(ConditionKey.IF_FALSE_CASE_KEY);
     }
 
     public void setFalseCaseExecutableItem(Executable falseCaseExecutableItem) {
-        this.addExecutable(FALSE_CASE_GROUP, falseCaseExecutableItem);
+        this.addExecutable(ConditionKey.IF_FALSE_CASE_KEY, falseCaseExecutableItem);
     }
 
     public void setIfNode(Node ifNode){
-        this.addExecutable(IF_ITEM, ifNode);
+        this.addExecutable(ConditionKey.IF_KEY, ifNode);
     }
 
     public Node getIfNode() {
-        return (Node) this.getExecutableOne(IF_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.IF_KEY);
     }
 }

+ 2 - 4
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java

@@ -14,8 +14,6 @@ import java.util.Iterator;
 
 public class IteratorCondition extends LoopCondition{
 
-    private final String ITERATOR_ITEM = "ITERATOR_ITEM";
-
     @Override
     public void execute(Integer slotIndex) throws Exception {
         Slot slot = DataBus.getSlot(slotIndex);
@@ -79,10 +77,10 @@ public class IteratorCondition extends LoopCondition{
     }
 
     public Node getIteratorNode() {
-        return (Node) this.getExecutableOne(ITERATOR_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.ITERATOR_KEY);
     }
 
     public void setIteratorNode(Node iteratorNode) {
-        this.addExecutable(ITERATOR_ITEM, iteratorNode);
+        this.addExecutable(ConditionKey.ITERATOR_KEY, iteratorNode);
     }
 }

+ 4 - 8
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java

@@ -17,24 +17,20 @@ import java.util.function.Consumer;
  */
 public abstract class LoopCondition extends Condition {
 
-    private final String DO_ITEM = "DO_ITEM";
-
-    private final String BREAK_ITEM = "BREAK_ITEM";
-
     protected Node getBreakNode() {
-        return (Node) this.getExecutableOne(BREAK_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.BREAK_KEY);
     }
 
     public void setBreakNode(Node breakNode) {
-        this.addExecutable(BREAK_ITEM, breakNode);
+        this.addExecutable(ConditionKey.BREAK_KEY, breakNode);
     }
 
     protected Executable getDoExecutor() {
-        return this.getExecutableOne(DO_ITEM);
+        return this.getExecutableOne(ConditionKey.DO_KEY);
     }
 
     public void setDoExecutor(Executable executable) {
-        this.addExecutable(DO_ITEM, executable);
+        this.addExecutable(ConditionKey.DO_KEY, executable);
     }
 
     protected void setLoopIndex(Executable executableItem, int index){

+ 6 - 14
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/SwitchCondition.java

@@ -23,14 +23,6 @@ import java.util.List;
  * @since 2.8.0
  */
 public class SwitchCondition extends Condition{
-
-
-    private final String TARGET_ITEM = "TARGET_ITEM";
-
-    private final String DEFAULT_ITEM = "DEFAULT_ITEM";
-
-    private final String SWITCH_ITEM = "SWITCH_ITEM";
-
     private final String TAG_PREFIX = "tag";
     private final String TAG_FLAG = ":";
 
@@ -109,26 +101,26 @@ public class SwitchCondition extends Condition{
     }
 
     public void addTargetItem(Executable executable){
-        this.addExecutable(TARGET_ITEM, executable);
+        this.addExecutable(ConditionKey.SWITCH_TARGET_KEY, executable);
     }
 
     public List<Executable> getTargetList(){
-        return this.getExecutableList(TARGET_ITEM);
+        return this.getExecutableList(ConditionKey.SWITCH_TARGET_KEY);
     }
 
     public void setSwitchNode(Node switchNode) {
-        this.addExecutable(SWITCH_ITEM, switchNode);
+        this.addExecutable(ConditionKey.SWITCH_KEY, switchNode);
     }
 
     public Node getSwitchNode(){
-        return (Node) this.getExecutableOne(SWITCH_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.SWITCH_KEY);
     }
 
     public Executable getDefaultExecutor() {
-        return this.getExecutableOne(DEFAULT_ITEM);
+        return this.getExecutableOne(ConditionKey.SWITCH_DEFAULT_KEY);
     }
 
     public void setDefaultExecutor(Executable defaultExecutor) {
-        this.addExecutable(DEFAULT_ITEM, defaultExecutor);
+        this.addExecutable(ConditionKey.SWITCH_DEFAULT_KEY, defaultExecutor);
     }
 }

+ 4 - 8
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ThenCondition.java

@@ -21,10 +21,6 @@ import java.util.stream.Collectors;
  */
 public class ThenCondition extends Condition {
 
-	private final String PRE_ITEM = "PRE_ITEM";
-
-	private final String FINALLY_ITEM = "FINALLY_ITEM";
-
 	@Override
 	public ConditionTypeEnum getConditionType() {
 		return ConditionTypeEnum.TYPE_THEN;
@@ -79,18 +75,18 @@ public class ThenCondition extends Condition {
 	}
 
 	public List<PreCondition> getPreConditionList() {
-		return this.getExecutableList(PRE_ITEM).stream().map(executable -> (PreCondition) executable).collect(Collectors.toList());
+		return this.getExecutableList(ConditionKey.PRE_KEY).stream().map(executable -> (PreCondition) executable).collect(Collectors.toList());
 	}
 
 	public void addPreCondition(PreCondition preCondition){
-		this.addExecutable(PRE_ITEM, preCondition);
+		this.addExecutable(ConditionKey.PRE_KEY, preCondition);
 	}
 
 	public List<FinallyCondition> getFinallyConditionList() {
-		return this.getExecutableList(FINALLY_ITEM).stream().map(executable -> (FinallyCondition) executable).collect(Collectors.toList());
+		return this.getExecutableList(ConditionKey.FINALLY_KEY).stream().map(executable -> (FinallyCondition) executable).collect(Collectors.toList());
 	}
 
 	public void addFinallyCondition(FinallyCondition finallyCondition){
-		this.addExecutable(FINALLY_ITEM, finallyCondition);
+		this.addExecutable(ConditionKey.FINALLY_KEY, finallyCondition);
 	}
 }

+ 2 - 4
liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java

@@ -18,8 +18,6 @@ import com.yomahub.liteflow.util.LiteFlowProxyUtil;
  */
 public class WhileCondition extends LoopCondition{
 
-    private final String WHILE_ITEM = "WHILE_ITEM";
-
     @Override
     public void execute(Integer slotIndex) throws Exception {
         Slot slot = DataBus.getSlot(slotIndex);
@@ -77,10 +75,10 @@ public class WhileCondition extends LoopCondition{
     }
 
     public Node getWhileNode() {
-        return (Node) this.getExecutableOne(WHILE_ITEM);
+        return (Node) this.getExecutableOne(ConditionKey.WHILE_KEY);
     }
 
     public void setWhileNode(Node whileNode) {
-        this.addExecutable(WHILE_ITEM, whileNode);
+        this.addExecutable(ConditionKey.WHILE_KEY, whileNode);
     }
 }