Skip to content

Commit 7a78092

Browse files
committed
Merge pull request #30343 from divcon
* pr/30343: Polish contribution Use putIfAbsent in Netty5HeadersAdapter Closes gh-30343
2 parents 5deab3a + ea0340f commit 7a78092

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,11 +91,8 @@ public void setAll(Map<String, String> values) {
9191
@Override
9292
public Map<String, String> toSingleValueMap() {
9393
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
94-
this.headers.forEach(entry -> {
95-
if (!singleValueMap.containsKey(entry.getKey())) {
96-
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
97-
}
98-
});
94+
this.headers.forEach(entry -> singleValueMap.putIfAbsent(
95+
entry.getKey().toString(), entry.getValue().toString()));
9996
return singleValueMap;
10097
}
10198

spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,11 +89,8 @@ public void setAll(Map<String, String> values) {
8989
@Override
9090
public Map<String, String> toSingleValueMap() {
9191
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
92-
this.headers.forEach(entry -> {
93-
if (!singleValueMap.containsKey(entry.getKey())) {
94-
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
95-
}
96-
});
92+
this.headers.forEach(entry -> singleValueMap.putIfAbsent(
93+
entry.getKey().toString(), entry.getValue().toString()));
9794
return singleValueMap;
9895
}
9996

0 commit comments

Comments
 (0)