refactor: use Map.computeIfAbsent

This commit is contained in:
broDom
2017-07-03 17:10:58 +02:00
parent fb2dfce631
commit 524a5dbb0a
3 changed files with 5 additions and 34 deletions

View File

@@ -35,16 +35,11 @@ package sonia.scm.cli.config;
//~--- JDK imports ------------------------------------------------------------
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
*
* @author Sebastian Sdorra
@@ -148,15 +143,7 @@ public class ScmClientConfig
*/
public ServerConfig getConfig(String name)
{
ServerConfig config = serverConfigMap.get(name);
if (config == null)
{
config = new ServerConfig();
serverConfigMap.put(name, config);
}
return config;
return serverConfigMap.computeIfAbsent(name, k -> new ServerConfig());
}
/**

View File

@@ -211,15 +211,7 @@ public class SVNKitLogger extends SVNDebugLogAdapter
*/
private Logger getLogger(SVNLogType type)
{
Logger logger = loggerMap.get(type);
if (logger == null)
{
logger = LoggerFactory.getLogger(parseName(type.getName()));
loggerMap.put(type, logger);
}
return logger;
return loggerMap.computeIfAbsent(type, t -> LoggerFactory.getLogger(parseName(t.getName())));
}
//~--- fields ---------------------------------------------------------------

View File

@@ -81,15 +81,7 @@ public class MapCacheManager
@Override
public synchronized <K, V> MapCache<K, V> getCache(String name)
{
MapCache<K, V> cache = cacheMap.get(name);
if (cache == null)
{
cache = new MapCache<K, V>();
cacheMap.put(name, cache);
}
return cache;
return (MapCache<K, V>) cacheMap.computeIfAbsent(name, k -> new MapCache<K, V>());
}
//~--- fields ---------------------------------------------------------------