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

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • 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

              Unassigned Unassigned
              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