From f80778e74440d4334c08dbcdd9f58aa2e7c01219 Mon Sep 17 00:00:00 2001 From: LeoLee <512240816@qq.com> Date: Mon, 13 Dec 2021 15:04:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9EdataMapPut=E7=A7=81?= =?UTF-8?q?=E6=9C=89=E6=96=B9=E6=B3=95=E8=BF=9B=E8=A1=8CdataMap=E7=9A=84pu?= =?UTF-8?q?t=E6=93=8D=E4=BD=9C=EF=BC=8C=E5=9C=A8=E8=AF=A5=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E4=B8=AD=E4=BC=9A=E6=9C=89value=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E7=A9=BA=E9=80=BB=E8=BE=91.2.=E4=BD=BF=E7=94=A8ObjectUtil?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=AF=B9=E8=B1=A1=E5=88=A4=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/FlowExecutor.java | 8 +-- .../yomahub/liteflow/entity/data/AbsSlot.java | 63 ++++++------------- 2 files changed, 22 insertions(+), 49 deletions(-) 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); } }