Skip to content

Commit 89e25cc

Browse files
google-labs-jules[bot]vorburger
authored andcommitted
clean: Add missing JavaDoc (by Google Jules)
1 parent ab388d8 commit 89e25cc

7 files changed

Lines changed: 86 additions & 6 deletions

File tree

src/main/java/ch/vorburger/fswatch/DirectoryWatcher.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@
2929
*/
3030
public interface DirectoryWatcher extends Closeable {
3131

32+
/**
33+
* The kind of change that occurred.
34+
*/
3235
enum ChangeKind {
33-
MODIFIED, DELETED, CREATED
36+
37+
/** Directory or file was modified. */
38+
MODIFIED,
39+
40+
/** Directory or file was deleted. */
41+
DELETED,
42+
43+
/** Directory or file was created. */
44+
CREATED
3445
}
3546

3647
/**
@@ -50,10 +61,16 @@ interface Listener {
5061
* Handles exceptions which occur during Listener onChange().
5162
*/
5263
interface ExceptionHandler {
64+
/**
65+
* Called when an exception occurs.
66+
* @param t the exception
67+
*/
5368
void onException(Throwable t);
5469
}
5570

56-
@Override String toString();
71+
@Override
72+
String toString();
5773

58-
@Override void close(); // do NOT throws (IO)Exception
74+
@Override
75+
void close(); // do NOT throws (IO)Exception
5976
}

src/main/java/ch/vorburger/fswatch/DirectoryWatcherBuilder.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,20 @@ public class DirectoryWatcherBuilder {
5050
protected ChangeKind[] eventKinds = { ChangeKind.DELETED, ChangeKind.MODIFIED };
5151
protected boolean existingFiles = false;
5252

53+
/**
54+
* Set the path to watch.
55+
* @param directory the path to watch
56+
* @return this
57+
*/
5358
public DirectoryWatcherBuilder path(File directory) {
5459
return path(directory.toPath());
5560
}
5661

62+
/**
63+
* Set the path to watch.
64+
* @param directory the path to watch
65+
* @return this
66+
*/
5767
public DirectoryWatcherBuilder path(Path directory) {
5868
if (path != null) {
5969
throw new IllegalStateException("path already set");
@@ -62,6 +72,11 @@ public DirectoryWatcherBuilder path(Path directory) {
6272
return this;
6373
}
6474

75+
/**
76+
* Set the listener to be notified of changes.
77+
* @param listener the listener to be notified of changes
78+
* @return this
79+
*/
6580
public DirectoryWatcherBuilder listener(Listener listener) {
6681
if (this.listener != null) {
6782
throw new IllegalStateException("listener already set");
@@ -70,16 +85,31 @@ public DirectoryWatcherBuilder listener(Listener listener) {
7085
return this;
7186
}
7287

88+
/**
89+
* Set the change kinds to listen for.
90+
* @param eventKinds the change kinds to listen for
91+
* @return this
92+
*/
7393
public DirectoryWatcherBuilder eventKinds(ChangeKind... eventKinds) {
7494
this.eventKinds = eventKinds;
7595
return this;
7696
}
7797

98+
/**
99+
* Set the exception handler.
100+
* @param exceptionHandler the exception handler
101+
* @return this
102+
*/
78103
public DirectoryWatcherBuilder exceptionHandler(ExceptionHandler exceptionHandler) {
79104
this.exceptionHandler = requireNonNull(exceptionHandler);
80105
return this;
81106
}
82107

108+
/**
109+
* Set the quiet period in milliseconds.
110+
* @param quietPeriodInMS the quiet period in milliseconds
111+
* @return this
112+
*/
83113
public DirectoryWatcherBuilder quietPeriodInMS(long quietPeriodInMS) {
84114
this.quietPeriodInMS = quietPeriodInMS;
85115
return this;

src/main/java/ch/vorburger/fswatch/DirectoryWatcherImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* @author Michael Vorburger.ch
5252
*/
5353
// intentionally package local, for now
54-
public class DirectoryWatcherImpl implements DirectoryWatcher {
54+
class DirectoryWatcherImpl implements DirectoryWatcher {
5555
private final static Logger log = LoggerFactory.getLogger(DirectoryWatcherImpl.class);
5656

5757
protected final WatchService watcher = FileSystems.getDefault().newWatchService(); // better final, as it will be accessed by both threads (normally OK either way, but still)

src/main/java/ch/vorburger/fswatch/DirectoryWatcherMain.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
*/
3333
public class DirectoryWatcherMain {
3434

35+
/**
36+
* Main method.
37+
* @param args command line arguments
38+
* @throws IOException if an I/O error occurs
39+
* @throws InterruptedException if the thread is interrupted
40+
*/
3541
public static void main(String[] args) throws IOException, InterruptedException {
3642
if (args.length < 1) {
3743
System.err.println("USAGE: <root-directory-to-watch-for-changes>");

src/main/java/ch/vorburger/fswatch/FileWatcherBuilder.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@
3333
*/
3434
public class FileWatcherBuilder extends DirectoryWatcherBuilder {
3535

36+
/**
37+
* Set the path to watch.
38+
* @param fileNotDirectory the path to watch
39+
* @return this
40+
*/
3641
@Override
3742
public FileWatcherBuilder path(File fileNotDirectory) {
3843
return (FileWatcherBuilder) super.path(fileNotDirectory.getAbsoluteFile());
3944
}
4045

46+
/**
47+
* Set the path to watch.
48+
* @param fileNotDirectory the path to watch
49+
* @return this
50+
*/
4151
@Override
4252
public FileWatcherBuilder path(Path fileNotDirectory) {
4353
return (FileWatcherBuilder) super.path(fileNotDirectory.toAbsolutePath());
@@ -57,9 +67,11 @@ public DirectoryWatcher build() throws IOException {
5767
"When using FileWatcherBuilder, set path() to a single file, not a directory (use DirectoryWatcherBuilder to watch a directory, and it's subdirectories)");
5868
}
5969
// NOTE We do want to wrap the FileWatcherListener inside the QuietPeriodListener, and not the other way around!
60-
Listener wrap = getQuietListener(new FileWatcherListener(path, listener));
70+
Listener fileWatcherListener = new FileWatcherListener(path, listener);
71+
Listener wrap = getQuietListener(fileWatcherListener);
6172
Path parent = path.getParent();
62-
if (parent == null) throw new IllegalArgumentException("path does not have a parent: " + path);
73+
if (parent == null)
74+
throw new IllegalArgumentException("path does not have a parent: " + path);
6375
DirectoryWatcherImpl watcher = new DirectoryWatcherImpl(false, parent, wrap, fileFilter,
6476
exceptionHandler, eventKinds);
6577
firstListenerNotification();
@@ -74,6 +86,11 @@ protected static class FileWatcherListener implements Listener {
7486
private final Listener delegate;
7587
private final Path fileToWatch;
7688

89+
/**
90+
* Constructor.
91+
* @param fileToWatch the file to watch
92+
* @param listenerToWrap the listener to wrap
93+
*/
7794
protected FileWatcherListener(Path fileToWatch, Listener listenerToWrap) {
7895
this.fileToWatch = fileToWatch;
7996
delegate = listenerToWrap;

src/main/java/ch/vorburger/fswatch/QuietPeriodListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public class QuietPeriodListener implements Listener {
4040
protected @Nullable Thread thread;
4141
protected volatile boolean sleepAgain;
4242

43+
/**
44+
* Constructor.
45+
* @param quietPeriodInMS the quiet period in milliseconds
46+
* @param listenerToWrap the listener to wrap
47+
* @param exceptionHandler the exception handler
48+
*/
4349
public QuietPeriodListener(long quietPeriodInMS, Listener listenerToWrap, ExceptionHandler exceptionHandler) {
4450
this.quietPeriodInMS = quietPeriodInMS;
4551
this.delegate = listenerToWrap;

src/main/java/ch/vorburger/fswatch/package-info.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20+
21+
/**
22+
* Watch a directory and be notified on your Listener for changes in it.
23+
*/
2024
@NullMarked
2125
package ch.vorburger.fswatch;
2226

0 commit comments

Comments
 (0)