Browse Source

Use putIfAbsent in Netty5HeadersAdapter

See gh-30343
pull/30420/head
divcon 3 years ago committed by Stephane Nicoll
parent
commit
f79d145b4c
  1. 10
      spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java
  2. 10
      spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -91,11 +91,9 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
@Override @Override
public Map<String, String> toSingleValueMap() { public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size()); Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.forEach(entry -> { this.headers.forEach(entry ->
if (!singleValueMap.containsKey(entry.getKey())) { singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString())
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString()); );
}
});
return singleValueMap; return singleValueMap;
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -89,11 +89,9 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
@Override @Override
public Map<String, String> toSingleValueMap() { public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size()); Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.forEach(entry -> { this.headers.forEach(entry ->
if (!singleValueMap.containsKey(entry.getKey())) { singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString())
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString()); );
}
});
return singleValueMap; return singleValueMap;
} }

Loading…
Cancel
Save