File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
src/main/java/engineering/swat/watch/impl/mac Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change 2626 */
2727package engineering .swat .watch .impl .mac ;
2828
29+ import static java .nio .file .StandardWatchEventKinds .ENTRY_CREATE ;
30+ import static java .nio .file .StandardWatchEventKinds .ENTRY_DELETE ;
31+ import static java .nio .file .StandardWatchEventKinds .ENTRY_MODIFY ;
32+ import static java .nio .file .StandardWatchEventKinds .OVERFLOW ;
33+
34+ import java .nio .file .Path ;
2935import java .nio .file .WatchEvent ;
30- import java .nio .file .WatchEvent .Kind ;
3136
3237import org .checkerframework .checker .nullness .qual .Nullable ;
3338
5156 */
5257@ FunctionalInterface
5358interface NativeEventHandler {
54- <T > void handle (Kind <T > kind , @ Nullable T context );
59+ <T > void handle (java .nio .file .WatchEvent .Kind <T > kind , @ Nullable T context );
60+
61+ default void handle (int kindOrdinal , String rootPath , String relativePath ) {
62+ if (kindOrdinal == Kind .OVERFLOW .ordinal ()) {
63+ handle (OVERFLOW , null );
64+ } else {
65+ var context = Path .of (rootPath ).relativize (Path .of (relativePath ));
66+ var kind =
67+ kindOrdinal == Kind .CREATE .ordinal () ? ENTRY_CREATE :
68+ kindOrdinal == Kind .MODIFY .ordinal () ? ENTRY_MODIFY :
69+ kindOrdinal == Kind .DELETE .ordinal () ? ENTRY_DELETE : null ;
70+
71+ if (kind != null ) {
72+ handle (kind , context );
73+ }
74+ }
75+ }
76+ }
77+
78+ enum Kind {
79+ OVERFLOW ,
80+ CREATE ,
81+ DELETE ,
82+ MODIFY ;
5583}
You can’t perform that action at this time.
0 commit comments