Skip to content

Commit ef6cf3a

Browse files
jiang4yuCharles7c
authored andcommitted
refactor(core): MapUtils#mergeMap 调整为使用for-each循环语法,自动处理迭代器的创建和遍历过程,提升安全性
1 parent 580aa00 commit ef6cf3a

File tree

1 file changed

+4
-6
lines changed
  • continew-starter-core/src/main/java/top/continew/starter/core/util

1 file changed

+4
-6
lines changed

continew-starter-core/src/main/java/top/continew/starter/core/util/MapUtils.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,15 @@ public static Map<String, Object> mergeMap(Map<String, Object> to, Map<String, O
6363
if (MapUtil.isEmpty(to) && MapUtil.isEmpty(from)) {
6464
return new HashMap<>();
6565
}
66-
Set<Map.Entry<String, Object>> entries = to.entrySet();
67-
Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
68-
while (iterator.hasNext()) {
69-
Map.Entry<String, Object> kv = iterator.next();
66+
67+
for (Map.Entry<String, Object> kv : to.entrySet()) {
7068
String toKey = kv.getKey();
7169
Object toValue = kv.getValue();
7270
Object fromValue = from.get(toKey);
7371
if (fromValue != null) {
7472
if (toValue instanceof Map) {
75-
Map<String, Object> childTo = (Map<String, Object>)toValue;
76-
mergeMap(childTo, (Map<String, Object>)fromValue);
73+
Map<String, Object> childTo = (Map<String, Object>) toValue;
74+
mergeMap(childTo, (Map<String, Object>) fromValue);
7775
} else {
7876
to.put(toKey, fromValue);
7977
}

0 commit comments

Comments
 (0)