Skip to content

Commit

Permalink
优化规则数据上下文处理
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jul 26, 2022
1 parent bd5e746 commit e08681a
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.jetlinks.rule.engine.api;


import com.google.common.collect.Maps;
import org.hswebframework.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

public class RuleDataHelper {
Expand Down Expand Up @@ -124,20 +126,20 @@ public static RuleData markSyncReturn(RuleData data, String endWithId) {

@SuppressWarnings("all")
public static Map<String, Object> toContextMap(RuleData ruleData) {
Map<String, Object> map = new HashMap<>(16);
Map<String, Object> map = Maps.newHashMapWithExpectedSize(32);
ruleData.acceptMap(_map -> {
map.putAll(_map);
});
if (map.isEmpty()) {
map.put("data", ruleData.getData());
}
map.compute("headers", (key, value) -> {
Map<String, Object> newHeader = new ConcurrentHashMap<>(ruleData.getHeaders());
if (value instanceof Map) {
Map<String, Object> newHeader = new HashMap<>(ruleData.getHeaders());
newHeader.putAll((Map) value);
return newHeader;
}
return ruleData.getHeaders();
return newHeader;
});
return map;
}
Expand Down

0 comments on commit e08681a

Please sign in to comment.