diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index c31ece721..5acda6a36 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -304,7 +304,7 @@ public class FlowExecutor { */ public T execute(String chainId, Object param, Class slotClazz, Integer slotIndex, boolean isInnerChain) throws Exception { - if (null == param) { + if (ObjectUtil.isNull(param)) { //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException throw new NullParamException("data slot can't accept null param"); } @@ -367,7 +367,7 @@ public class FlowExecutor { */ public LiteflowResponse execute2Resp(String chainId, Object param, Class slotClazz, Integer slotIndex, boolean isInnerChain) { - if (null == param) { + if (ObjectUtil.isNull(param)) { //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException throw new NullParamException("data slot can't accept null param"); } @@ -434,13 +434,13 @@ public class FlowExecutor { if (!isInnerChain) { //对param进行判空,如果为null,则不进行slot设置 - if (null != param) { + if (ObjectUtil.isNotNull(param)) { slot.setRequestData(param); } slot.setChainName(chainId); } else { //对param进行判空,如果为null,则不进行slot设置 - if (null != param) { + if (ObjectUtil.isNotNull(param)) { slot.setChainReqData(chainId, param); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java index f7d080db3..f6f24706d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/data/AbsSlot.java @@ -7,6 +7,7 @@ */ package com.yomahub.liteflow.entity.data; +import cn.hutool.core.util.ObjectUtil; import com.yomahub.liteflow.exception.NullParamException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,6 +49,14 @@ public abstract class AbsSlot implements Slot { protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); + private void dataMapPut(String key, T t) { + if (ObjectUtil.isNull(t)) { + //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException + throw new NullParamException("data slot can't accept null param"); + } + dataMap.put(key, t); + } + public T getInput(String nodeId){ return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); } @@ -57,19 +66,11 @@ public abstract class AbsSlot implements Slot { } public void setInput(String nodeId,T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(NODE_INPUT_PREFIX + nodeId, t); + dataMapPut(NODE_INPUT_PREFIX + nodeId, t); } public void setOutput(String nodeId,T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t); + dataMapPut(NODE_OUTPUT_PREFIX + nodeId, t); } public T getRequestData(){ @@ -77,11 +78,7 @@ public abstract class AbsSlot implements Slot { } public void setRequestData(T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(REQUEST, t); + dataMapPut(REQUEST, t); } public T getResponseData(){ @@ -89,11 +86,7 @@ public abstract class AbsSlot implements Slot { } public void setResponseData(T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(RESPONSE, t); + dataMapPut(RESPONSE, t); } public T getChainReqData(String chainId) { @@ -101,11 +94,7 @@ public abstract class AbsSlot implements Slot { } public void setChainReqData(String chainId, T t) { - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(CHAIN_REQ_PREFIX + chainId, t); + dataMapPut(CHAIN_REQ_PREFIX + chainId, t); } public boolean hasData(String key){ @@ -117,11 +106,7 @@ public abstract class AbsSlot implements Slot { } public void setData(String key, T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(key, t); + dataMapPut(key, t); } public void setPrivateDeliveryData(String nodeId, T t){ @@ -149,11 +134,7 @@ public abstract class AbsSlot implements Slot { } public void setCondResult(String key, T t){ - if (null == t) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(COND_NODE_PREFIX + key, t); + dataMapPut(COND_NODE_PREFIX + key, t); } public T getCondResult(String key){ @@ -161,11 +142,7 @@ public abstract class AbsSlot implements Slot { } public void setChainName(String chainName) { - if (null == chainName) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - dataMap.put(CHAINNAME, chainName); + dataMapPut(CHAINNAME, chainName); } public String getChainName() { @@ -211,10 +188,6 @@ public abstract class AbsSlot implements Slot { @Override public void setException(Exception e) { - if (null == e) { - //data slot is a ConcurrentHashMap, so null value will trigger NullPointerException - throw new NullParamException("data slot can't accept null param"); - } - this.dataMap.put(EXCEPTION, e); + dataMapPut(EXCEPTION, e); } }