Set<WatchRequest> (@NotNull Collection<WatchRequest> requestsToRemove, @NotNull Collection<String> recursiveRootsToAdd, @NotNull Collection<String> flatRootsToAdd) { Set<WatchRequest> recursiveRequestsToRemove = new HashSet<>(), flatRequestsToRemove = new HashSet<>(); requestsToRemove.forEach(req -> (req.isToWatchRecursively() ? recursiveRequestsToRemove : flatRequestsToRemove).add(req)); Set<WatchRequest> result = new HashSet<>(recursiveRootsToAdd.size() + flatRootsToAdd.size()); synchronized (myLock) { updateWatchRoots(recursiveRootsToAdd, recursiveRequestsToRemove, result, myRecursiveWatchRoots, true); updateWatchRoots(flatRootsToAdd, flatRequestsToRemove, result, myFlatWatchRoots, false); if (myWatcherRequiresUpdate) { updateFileWatcher(); } } return result; }