Browse Source

Use Map.computeIfAbsent() where feasible

See gh-31916
pull/31920/head
Yanming Zhou 2 years ago committed by Stéphane Nicoll
parent
commit
ea5ef098cf
  1. 6
      spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java
  2. 6
      spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java

6
spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java

@ -284,11 +284,7 @@ public class FactoryBeanTests { @@ -284,11 +284,7 @@ public class FactoryBeanTests {
if (bean instanceof FactoryBean) {
return bean;
}
AtomicInteger c = count.get(beanName);
if (c == null) {
c = new AtomicInteger();
count.put(beanName, c);
}
AtomicInteger c = count.computeIfAbsent(beanName, k -> new AtomicInteger());
c.incrementAndGet();
return bean;
}

6
spring-websocket/src/main/java/org/springframework/web/socket/server/standard/SpringConfigurator.java

@ -102,11 +102,7 @@ public class SpringConfigurator extends Configurator { @@ -102,11 +102,7 @@ public class SpringConfigurator extends Configurator {
private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) {
String wacId = wac.getId();
Map<Class<?>, String> beanNamesByType = cache.get(wacId);
if (beanNamesByType == null) {
beanNamesByType = new ConcurrentHashMap<>();
cache.put(wacId, beanNamesByType);
}
Map<Class<?>, String> beanNamesByType = cache.computeIfAbsent(wacId, k -> new ConcurrentHashMap<>());
if (!beanNamesByType.containsKey(endpointClass)) {
String[] names = wac.getBeanNamesForType(endpointClass);

Loading…
Cancel
Save