3333 * limit the files and directories visited.
3434 * Commons IO supplies many common filter implementations in the
3535 * <a href="filefilter/package-summary.html"> filefilter</a> package.
36+ * </p>
3637 * <p>
3738 * The following sections describe:
39+ * </p>
3840 * <ul>
3941 * <li><a href="#example">1. Example Implementation</a> - example
4042 * <code>FileCleaner</code> implementation.</li>
8284 *
8385 * <h3 id="filter">2. Filter Example</h3>
8486 *
87+ * <p>
8588 * Choosing which directories and files to process can be a key aspect
8689 * of using this class. This information can be setup in three ways,
8790 * via three different constructors.
91+ * </p>
8892 * <p>
8993 * The first option is to visit all directories and files.
9094 * This is achieved via the no-args constructor.
95+ * </p>
9196 * <p>
9297 * The second constructor option is to supply a single {@link FileFilter}
9398 * that describes the files and directories to visit. Care must be taken
9499 * with this option as the same filter is used for both directories
95100 * and files.
101+ * </p>
96102 * <p>
97103 * For example, if you wanted all directories which are not hidden
98104 * and files which end in ".txt":
105+ * </p>
99106 * <pre>
100107 * public class FooDirectoryWalker extends DirectoryWalker {
101108 * public FooDirectoryWalker(FileFilter filter) {
127134 * the correct <code>FileFilter</code>, something which is very easy to
128135 * get wrong when attempted manually, particularly when trying to
129136 * express constructs like 'any file in directories named docs'.
137+ * </p>
130138 * <p>
131139 * For example, if you wanted all directories which are not hidden
132140 * and files which end in ".txt":
141+ * </p>
133142 * <pre>
134143 * public class FooDirectoryWalker extends DirectoryWalker {
135144 * public FooDirectoryWalker(IOFileFilter dirFilter, IOFileFilter fileFilter) {
143152 * FileFilterUtils.suffixFileFilter(".txt"),
144153 * );
145154 * </pre>
155+ * <p>
146156 * This is much simpler than the previous example, and is why it is the preferred
147157 * option for filtering.
158+ * </p>
148159 *
149160 * <h3 id="cancel">3. Cancellation</h3>
150161 *
162+ * <p>
151163 * The DirectoryWalker contains some of the logic required for cancel processing.
152164 * Subclasses must complete the implementation.
165+ * </p>
153166 * <p>
154167 * What <code>DirectoryWalker</code> does provide for cancellation is:
168+ * </p>
155169 * <ul>
156170 * <li>{@link CancelException} which can be thrown in any of the
157171 * <i>lifecycle</i> methods to stop processing.</li>
161175 * </ul>
162176 * <p>
163177 * Implementations need to provide:
178+ * </p>
164179 * <ul>
165180 * <li>The decision logic on whether to cancel processing or not.</li>
166181 * <li>Constructing and throwing a {@link CancelException}.</li>
167182 * <li>Custom cancel processing in the <code>handleCancelled()</code> method.
168183 * </ul>
169184 * <p>
170185 * Two possible scenarios are envisaged for cancellation:
186+ * </p>
171187 * <ul>
172188 * <li><a href="#external">3.1 External / Multi-threaded</a> - cancellation being
173189 * decided/initiated by an external process.</li>
177193 * <p>
178194 * The following sections provide example implementations for these two different
179195 * scenarios.
196+ * </p>
180197 *
181198 * <h4 id="external">3.1 External / Multi-threaded</h4>
182199 *
200+ * <p>
183201 * This example provides a public <code>cancel()</code> method that can be
184202 * called by another thread to stop the processing. A typical example use-case
185203 * would be a cancel button on a GUI. Calling this method sets a
189207 * will cause the walk to stop immediately. The <code>handleCancelled()</code>
190208 * method will be the next, and last, callback method received once cancellation
191209 * has occurred.
210+ * </p>
192211 *
193212 * <pre>
194213 * public class FooDirectoryWalker extends DirectoryWalker {
211230 *
212231 * <h4 id="internal">3.2 Internal</h4>
213232 *
233+ * <p>
214234 * This shows an example of how internal cancellation processing could be implemented.
215235 * <b>Note</b> the decision logic and throwing a {@link CancelException} could be implemented
216236 * in any of the <i>lifecycle</i> methods.
237+ * </p>
217238 *
218239 * <pre>
219240 * public class BarDirectoryWalker extends DirectoryWalker {
241262 * </pre>
242263 *
243264 * @since 1.3
244- * @version $Id$
265+ *
245266 */
246267public abstract class DirectoryWalker <T > {
247268
@@ -262,12 +283,13 @@ protected DirectoryWalker() {
262283 }
263284
264285 /**
265- * Construct an instance with a filter and limit the <i>depth</i> navigated to.
286+ * Constructs an instance with a filter and limit the <i>depth</i> navigated to.
266287 * <p>
267288 * The filter controls which files and directories will be navigated to as
268289 * part of the walk. The {@link FileFilterUtils} class is useful for combining
269290 * various filters together. A {@code null} filter means that no
270291 * filtering should occur and all files and directories will be visited.
292+ * </p>
271293 *
272294 * @param filter the filter to apply, null means visit all files
273295 * @param depthLimit controls how <i>deep</i> the hierarchy is
@@ -279,13 +301,14 @@ protected DirectoryWalker(final FileFilter filter, final int depthLimit) {
279301 }
280302
281303 /**
282- * Construct an instance with a directory and a file filter and an optional
304+ * Constructs an instance with a directory and a file filter and an optional
283305 * limit on the <i>depth</i> navigated to.
284306 * <p>
285307 * The filters control which files and directories will be navigated to as part
286308 * of the walk. This constructor uses {@link FileFilterUtils#makeDirectoryOnly(IOFileFilter)}
287309 * and {@link FileFilterUtils#makeFileOnly(IOFileFilter)} internally to combine the filters.
288310 * A {@code null} filter means that no filtering should occur.
311+ * </p>
289312 *
290313 * @param directoryFilter the filter to apply to directories, null means visit all directories
291314 * @param fileFilter the filter to apply to files, null means visit all files
@@ -311,10 +334,12 @@ protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter,
311334 * <p>
312335 * Users of this class do not need to call this method. This method will
313336 * be called automatically by another (public) method on the specific subclass.
337+ * </p>
314338 * <p>
315339 * Writers of subclasses should call this method to start the directory walk.
316340 * Once called, this method will emit events as it walks the hierarchy.
317341 * The event methods have the prefix <code>handle</code>.
342+ * </p>
318343 *
319344 * @param startDirectory the directory to start from, not null
320345 * @param results the collection of result objects, may be updated
@@ -379,6 +404,7 @@ private void walk(final File directory, final int depth, final Collection<T> res
379404 * automatically by the walk of the tree. However, sometimes a single method,
380405 * typically {@link #handleFile}, may take a long time to run. In that case,
381406 * you may wish to check for cancellation by calling this method.
407+ * </p>
382408 *
383409 * @param file the current file being processed
384410 * @param depth the current file level (starting directory = 0)
@@ -399,6 +425,7 @@ protected final void checkIfCancelled(final File file, final int depth, final Co
399425 * This method should be implemented by those subclasses that want to
400426 * provide a public <code>cancel()</code> method available from another
401427 * thread. The design pattern for the subclass should be as follows:
428+ * </p>
402429 * <pre>
403430 * public class FooDirectoryWalker extends DirectoryWalker {
404431 * private volatile boolean cancelled = false;
@@ -418,8 +445,10 @@ protected final void checkIfCancelled(final File file, final int depth, final Co
418445 * <p>
419446 * If this method returns true, then the directory walk is immediately
420447 * cancelled. The next callback method will be {@link #handleCancelled}.
448+ * </p>
421449 * <p>
422450 * This implementation returns false.
451+ * </p>
423452 *
424453 * @param file the file or directory being processed
425454 * @param depth the current directory level (starting directory = 0)
@@ -439,6 +468,7 @@ protected boolean handleIsCancelled(
439468 * obtained from the exception.
440469 * <p>
441470 * This implementation just re-throws the {@link CancelException}.
471+ * </p>
442472 *
443473 * @param startDirectory the directory that the walk started from
444474 * @param results the collection of result objects, may be updated
@@ -457,6 +487,7 @@ protected void handleCancelled(final File startDirectory, final Collection<T> re
457487 * Overridable callback method invoked at the start of processing.
458488 * <p>
459489 * This implementation does nothing.
490+ * </p>
460491 *
461492 * @param startDirectory the directory to start from
462493 * @param results the collection of result objects, may be updated
@@ -472,8 +503,10 @@ protected void handleStart(final File startDirectory, final Collection<T> result
472503 * This method returns a boolean to indicate if the directory should be examined or not.
473504 * If you return false, the entire directory and any subdirectories will be skipped.
474505 * Note that this functionality is in addition to the filtering by file filter.
506+ * </p>
475507 * <p>
476508 * This implementation does nothing and returns true.
509+ * </p>
477510 *
478511 * @param directory the current directory being processed
479512 * @param depth the current directory level (starting directory = 0)
@@ -491,6 +524,7 @@ protected boolean handleDirectory(final File directory, final int depth, final C
491524 * Overridable callback method invoked at the start of processing each directory.
492525 * <p>
493526 * This implementation does nothing.
527+ * </p>
494528 *
495529 * @param directory the current directory being processed
496530 * @param depth the current directory level (starting directory = 0)
@@ -506,6 +540,7 @@ protected void handleDirectoryStart(final File directory, final int depth, final
506540 * Overridable callback method invoked with the contents of each directory.
507541 * <p>
508542 * This implementation returns the files unchanged
543+ * </p>
509544 *
510545 * @param directory the current directory being processed
511546 * @param depth the current directory level (starting directory = 0)
@@ -523,6 +558,7 @@ protected File[] filterDirectoryContents(final File directory, final int depth,
523558 * Overridable callback method invoked for each (non-directory) file.
524559 * <p>
525560 * This implementation does nothing.
561+ * </p>
526562 *
527563 * @param file the current file being processed
528564 * @param depth the current directory level (starting directory = 0)
@@ -537,6 +573,7 @@ protected void handleFile(final File file, final int depth, final Collection<T>
537573 * Overridable callback method invoked for each restricted directory.
538574 * <p>
539575 * This implementation does nothing.
576+ * </p>
540577 *
541578 * @param directory the restricted directory
542579 * @param depth the current directory level (starting directory = 0)
@@ -552,6 +589,7 @@ protected void handleRestricted(final File directory, final int depth, final Col
552589 * Overridable callback method invoked at the end of processing each directory.
553590 * <p>
554591 * This implementation does nothing.
592+ * </p>
555593 *
556594 * @param directory the directory being processed
557595 * @param depth the current directory level (starting directory = 0)
@@ -567,6 +605,7 @@ protected void handleDirectoryEnd(final File directory, final int depth, final C
567605 * Overridable callback method invoked at the end of processing.
568606 * <p>
569607 * This implementation does nothing.
608+ * </p>
570609 *
571610 * @param results the collection of result objects, may be updated
572611 * @throws IOException if an I/O Error occurs
@@ -617,7 +656,7 @@ public CancelException(final String message, final File file, final int depth) {
617656 }
618657
619658 /**
620- * Return the file when the operation was cancelled.
659+ * Returns the file when the operation was cancelled.
621660 *
622661 * @return the file when the operation was cancelled
623662 */
@@ -626,7 +665,7 @@ public File getFile() {
626665 }
627666
628667 /**
629- * Return the depth when the operation was cancelled.
668+ * Returns the depth when the operation was cancelled.
630669 *
631670 * @return the depth when the operation was cancelled
632671 */
0 commit comments