Skip to content

Commit 62f4b1c

Browse files
committed
Move updateChildWatches to inner class
1 parent 671d5eb commit 62f4b1c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import org.apache.logging.log4j.LogManager;
3939
import org.apache.logging.log4j.Logger;
40+
import org.checkerframework.checker.initialization.qual.NotOnlyInitialized;
4041

4142
import engineering.swat.watch.WatchEvent;
4243
import engineering.swat.watch.WatchScope;
@@ -45,30 +46,30 @@
4546
public class JDKFileTreeWatch extends JDKBaseWatch {
4647
private final Logger logger = LogManager.getLogger();
4748
private final Map<Path, JDKFileTreeWatch> childWatches = new ConcurrentHashMap<>();
48-
private final JDKBaseWatch internal;
49+
private final @NotOnlyInitialized JDKBaseWatch internal;
4950

5051
public JDKFileTreeWatch(Path root, Executor exec,
5152
BiConsumer<EventHandlingWatch, WatchEvent> eventHandler) {
5253

5354
super(root, exec, eventHandler);
54-
var internalEventHandler = updateChildWatches().andThen(eventHandler);
55+
var internalEventHandler = new ChildWatchesUpdater().andThen(eventHandler);
5556
this.internal = new JDKDirectoryWatch(root, exec, internalEventHandler);
5657
}
5758

5859
/**
59-
* @return An event handler that updates the child watches according to the
60-
* following rules: (a) when an overflow happens, it's propagated to each
61-
* existing child watch; (b) when a subdirectory creation happens, a new
62-
* child watch is opened for that subdirectory; (c) when a subdirectory
63-
* deletion happens, an existing child watch is closed for that
64-
* subdirectory.
60+
* Event handler that updates the child watches according to the following
61+
* rules: (a) when an overflow happens, it's propagated to each existing
62+
* child watch; (b) when a subdirectory creation happens, a new child watch
63+
* is opened for that subdirectory; (c) when a subdirectory deletion
64+
* happens, an existing child watch is closed for that subdirectory.
6565
*/
66-
private BiConsumer<EventHandlingWatch, WatchEvent> updateChildWatches() {
67-
return (watch, event) -> {
66+
private class ChildWatchesUpdater implements BiConsumer<EventHandlingWatch, WatchEvent> {
67+
@Override
68+
public void accept(EventHandlingWatch watch, WatchEvent event) {
6869
var kind = event.getKind();
6970

7071
if (kind == WatchEvent.Kind.OVERFLOW) {
71-
forEachChild(this::reportOverflowToChildWatch);
72+
forEachChild(JDKFileTreeWatch.this::reportOverflowToChildWatch);
7273
return;
7374
}
7475

@@ -83,11 +84,10 @@ private BiConsumer<EventHandlingWatch, WatchEvent> updateChildWatches() {
8384
// event for the watch.
8485
reportOverflowToChildWatch(child);
8586
}
86-
8787
if (kind == WatchEvent.Kind.DELETED && directory) {
8888
closeChildWatch(child);
8989
}
90-
};
90+
}
9191
}
9292

9393
private void openChildWatch(Path child) {

0 commit comments

Comments
 (0)