Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-4032

Use `Map.computeIfAbsent` instead of `if Map.get is null then put value`

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: server

      Description

      In this method

      WatchManager.addWatch(String path, Watcher watcher, WatcherMode watcherMode)
      

      use

      Map.computeIfAbsent
      

      simplify code like

              Set<String> paths = watch2Paths.get(watcher);
              if (paths == null) {
                  paths = new HashSet<>();
                  watch2Paths.put(watcher, paths);
              }
      

      result:

      Set<String> paths = watch2Paths.computeIfAbsent(watcher, k -> new HashSet<>());
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                lan_ok LiAoNan
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h