Skip to content

Commit 47b8a10

Browse files
committed
Use computeIfAbsent instead of putIfAbsent
1 parent 36c4299 commit 47b8a10

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/engineering/swat/watch/impl/jdk/JDKFileTreeWatch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.Executor;
3535
import java.util.function.BiConsumer;
3636
import java.util.function.Consumer;
37+
import java.util.function.Function;
3738

3839
import org.apache.logging.log4j.LogManager;
3940
import org.apache.logging.log4j.Logger;
@@ -91,7 +92,7 @@ public void accept(EventHandlingWatch watch, WatchEvent event) {
9192
}
9293

9394
private void openChildWatch(Path child) {
94-
var childWatch = new JDKFileTreeWatch(child, exec, (w, e) ->
95+
Function<Path, JDKFileTreeWatch> newChildWatch = p -> new JDKFileTreeWatch(child, exec, (w, e) ->
9596
// Same as `eventHandler`, except each event is pre-processed such
9697
// that the last segment of the root path becomes the first segment
9798
// of the relative path. For instance, `foo/bar` (root path) and
@@ -102,7 +103,8 @@ private void openChildWatch(Path child) {
102103
eventHandler.accept(w, relativize(e))
103104
);
104105

105-
if (childWatches.putIfAbsent(child, childWatch) == null) {
106+
var childWatch = childWatches.computeIfAbsent(child, newChildWatch);
107+
if (childWatch != null) {
106108
try {
107109
childWatch.open();
108110
} catch (IOException e) {

0 commit comments

Comments
 (0)