You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "LiAoNan (Jira)" <ji...@apache.org> on 2020/12/22 08:51:00 UTC
[jira] [Created] (ZOOKEEPER-4032) Use `Map.computeIfAbsent` instead
of `if Map.get is null then put value`
LiAoNan created ZOOKEEPER-4032:
----------------------------------
Summary: Use `Map.computeIfAbsent` instead of `if Map.get is null then put value`
Key: ZOOKEEPER-4032
URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4032
Project: ZooKeeper
Issue Type: Improvement
Components: server
Reporter: LiAoNan
In this method
{code:java}
WatchManager.addWatch(String path, Watcher watcher, WatcherMode watcherMode)
{code}
use
{code:java}
Map.computeIfAbsent
{code}
simplify code like
{code:java}
Set<String> paths = watch2Paths.get(watcher);
if (paths == null) {
paths = new HashSet<>();
watch2Paths.put(watcher, paths);
}
{code}
result:
{code:java}
Set<String> paths = watch2Paths.computeIfAbsent(watcher, k -> new HashSet<>());
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)