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)

Reply via email to