You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@zookeeper.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/12/22 08:59:00 UTC
[jira] [Updated] (ZOOKEEPER-4032) Use `Map.computeIfAbsent` instead
of `if Map.get is null then put value`
[ https://issues.apache.org/jira/browse/ZOOKEEPER-4032?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
ASF GitHub Bot updated ZOOKEEPER-4032:
--------------------------------------
Labels: pull-request-available (was: )
> 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
> Priority: Major
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 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)