Skip to content

Commit 0a37082

Browse files
author
Niall Pemberton
committed
Change DirectoryWalker to use generified Collection
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@897578 13f79535-47bb-0310-9956-ffa450edef68
1 parent b9b0631 commit 0a37082

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/java/org/apache/commons/io/DirectoryWalker.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
* @since Commons IO 1.3
249249
* @version $Revision$
250250
*/
251-
public abstract class DirectoryWalker {
251+
public abstract class DirectoryWalker<T> {
252252

253253
/**
254254
* The file filter to use to filter files and directories.
@@ -326,7 +326,7 @@ protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter,
326326
* @throws NullPointerException if the start directory is null
327327
* @throws IOException if an I/O Error occurs
328328
*/
329-
protected final void walk(File startDirectory, Collection<?> results) throws IOException {
329+
protected final void walk(File startDirectory, Collection<T> results) throws IOException {
330330
if (startDirectory == null) {
331331
throw new NullPointerException("Start Directory is null");
332332
}
@@ -347,7 +347,7 @@ protected final void walk(File startDirectory, Collection<?> results) throws IOE
347347
* @param results the collection of result objects, may be updated
348348
* @throws IOException if an I/O Error occurs
349349
*/
350-
private void walk(File directory, int depth, Collection<?> results) throws IOException {
350+
private void walk(File directory, int depth, Collection<T> results) throws IOException {
351351
checkIfCancelled(directory, depth, results);
352352
if (handleDirectory(directory, depth, results)) {
353353
handleDirectoryStart(directory, depth, results);
@@ -390,7 +390,7 @@ private void walk(File directory, int depth, Collection<?> results) throws IOExc
390390
* @param results the collection of result objects, may be updated
391391
* @throws IOException if an I/O Error occurs
392392
*/
393-
protected final void checkIfCancelled(File file, int depth, Collection<?> results) throws IOException {
393+
protected final void checkIfCancelled(File file, int depth, Collection<T> results) throws IOException {
394394
if (handleIsCancelled(file, depth, results)) {
395395
throw new CancelException(file, depth);
396396
}
@@ -432,7 +432,7 @@ protected final void checkIfCancelled(File file, int depth, Collection<?> result
432432
* @throws IOException if an I/O Error occurs
433433
*/
434434
protected boolean handleIsCancelled(
435-
File file, int depth, Collection<?> results) throws IOException {
435+
File file, int depth, Collection<T> results) throws IOException {
436436
// do nothing - overridable by subclass
437437
return false; // not cancelled
438438
}
@@ -450,7 +450,7 @@ protected boolean handleIsCancelled(
450450
* containing details at the point of cancellation.
451451
* @throws IOException if an I/O Error occurs
452452
*/
453-
protected void handleCancelled(File startDirectory, Collection<?> results,
453+
protected void handleCancelled(File startDirectory, Collection<T> results,
454454
CancelException cancel) throws IOException {
455455
// re-throw exception - overridable by subclass
456456
throw cancel;
@@ -466,7 +466,7 @@ protected void handleCancelled(File startDirectory, Collection<?> results,
466466
* @param results the collection of result objects, may be updated
467467
* @throws IOException if an I/O Error occurs
468468
*/
469-
protected void handleStart(File startDirectory, Collection<?> results) throws IOException {
469+
protected void handleStart(File startDirectory, Collection<T> results) throws IOException {
470470
// do nothing - overridable by subclass
471471
}
472472

@@ -485,7 +485,7 @@ protected void handleStart(File startDirectory, Collection<?> results) throws IO
485485
* @return true to process this directory, false to skip this directory
486486
* @throws IOException if an I/O Error occurs
487487
*/
488-
protected boolean handleDirectory(File directory, int depth, Collection<?> results) throws IOException {
488+
protected boolean handleDirectory(File directory, int depth, Collection<T> results) throws IOException {
489489
// do nothing - overridable by subclass
490490
return true; // process directory
491491
}
@@ -500,7 +500,7 @@ protected boolean handleDirectory(File directory, int depth, Collection<?> resul
500500
* @param results the collection of result objects, may be updated
501501
* @throws IOException if an I/O Error occurs
502502
*/
503-
protected void handleDirectoryStart(File directory, int depth, Collection<?> results) throws IOException {
503+
protected void handleDirectoryStart(File directory, int depth, Collection<T> results) throws IOException {
504504
// do nothing - overridable by subclass
505505
}
506506

@@ -529,7 +529,7 @@ protected File[] filterDirectoryContents(File directory, int depth, File[] files
529529
* @param results the collection of result objects, may be updated
530530
* @throws IOException if an I/O Error occurs
531531
*/
532-
protected void handleFile(File file, int depth, Collection<?> results) throws IOException {
532+
protected void handleFile(File file, int depth, Collection<T> results) throws IOException {
533533
// do nothing - overridable by subclass
534534
}
535535

@@ -543,7 +543,7 @@ protected void handleFile(File file, int depth, Collection<?> results) throws IO
543543
* @param results the collection of result objects, may be updated
544544
* @throws IOException if an I/O Error occurs
545545
*/
546-
protected void handleRestricted(File directory, int depth, Collection<?> results) throws IOException {
546+
protected void handleRestricted(File directory, int depth, Collection<T> results) throws IOException {
547547
// do nothing - overridable by subclass
548548
}
549549

@@ -557,7 +557,7 @@ protected void handleRestricted(File directory, int depth, Collection<?> results
557557
* @param results the collection of result objects, may be updated
558558
* @throws IOException if an I/O Error occurs
559559
*/
560-
protected void handleDirectoryEnd(File directory, int depth, Collection<?> results) throws IOException {
560+
protected void handleDirectoryEnd(File directory, int depth, Collection<T> results) throws IOException {
561561
// do nothing - overridable by subclass
562562
}
563563

@@ -569,7 +569,7 @@ protected void handleDirectoryEnd(File directory, int depth, Collection<?> resul
569569
* @param results the collection of result objects, may be updated
570570
* @throws IOException if an I/O Error occurs
571571
*/
572-
protected void handleEnd(Collection<?> results) throws IOException {
572+
protected void handleEnd(Collection<T> results) throws IOException {
573573
// do nothing - overridable by subclass
574574
}
575575

src/test/org/apache/commons/io/DirectoryWalkerTestCase.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public void testMultiThreadCancel() {
371371
* Test DirectoryWalker implementation that finds files in a directory hierarchy
372372
* applying a file filter.
373373
*/
374-
private static class TestFileFinder extends DirectoryWalker {
374+
private static class TestFileFinder extends DirectoryWalker<File> {
375375

376376
protected TestFileFinder(FileFilter filter, int depthLimit) {
377377
super(filter, depthLimit);
@@ -394,13 +394,13 @@ protected List<File> find(File startDirectory) {
394394

395395
/** Handles a directory end by adding the File to the result set. */
396396
@Override
397-
protected void handleDirectoryEnd(File directory, int depth, Collection results) {
397+
protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) {
398398
results.add(directory);
399399
}
400400

401401
/** Handles a file by adding the File to the result set. */
402402
@Override
403-
protected void handleFile(File file, int depth, Collection results) {
403+
protected void handleFile(File file, int depth, Collection<File> results) {
404404
results.add(file);
405405
}
406406
}
@@ -419,7 +419,7 @@ protected TestFalseFileFinder(FileFilter filter, int depthLimit) {
419419

420420
/** Always returns false. */
421421
@Override
422-
protected boolean handleDirectory(File directory, int depth, Collection<?> results) {
422+
protected boolean handleDirectory(File directory, int depth, Collection<File> results) {
423423
return false;
424424
}
425425
}
@@ -430,7 +430,7 @@ protected boolean handleDirectory(File directory, int depth, Collection<?> resul
430430
* Test DirectoryWalker implementation that finds files in a directory hierarchy
431431
* applying a file filter.
432432
*/
433-
static class TestCancelWalker extends DirectoryWalker {
433+
static class TestCancelWalker extends DirectoryWalker<File> {
434434
private String cancelFileName;
435435
private boolean suppressCancel;
436436

@@ -449,7 +449,7 @@ protected List<File> find(File startDirectory) throws IOException {
449449

450450
/** Handles a directory end by adding the File to the result set. */
451451
@Override
452-
protected void handleDirectoryEnd(File directory, int depth, Collection results) throws IOException {
452+
protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) throws IOException {
453453
results.add(directory);
454454
if (cancelFileName.equals(directory.getName())) {
455455
throw new CancelException(directory, depth);
@@ -458,7 +458,7 @@ protected void handleDirectoryEnd(File directory, int depth, Collection results)
458458

459459
/** Handles a file by adding the File to the result set. */
460460
@Override
461-
protected void handleFile(File file, int depth, Collection results) throws IOException {
461+
protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
462462
results.add(file);
463463
if (cancelFileName.equals(file.getName())) {
464464
throw new CancelException(file, depth);
@@ -467,7 +467,7 @@ protected void handleFile(File file, int depth, Collection results) throws IOExc
467467

468468
/** Handles Cancel. */
469469
@Override
470-
protected void handleCancelled(File startDirectory, Collection<?> results,
470+
protected void handleCancelled(File startDirectory, Collection<File> results,
471471
CancelException cancel) throws IOException {
472472
if (!suppressCancel) {
473473
super.handleCancelled(startDirectory, results, cancel);
@@ -479,7 +479,7 @@ protected void handleCancelled(File startDirectory, Collection<?> results,
479479
* Test DirectoryWalker implementation that finds files in a directory hierarchy
480480
* applying a file filter.
481481
*/
482-
static class TestMultiThreadCancelWalker extends DirectoryWalker {
482+
static class TestMultiThreadCancelWalker extends DirectoryWalker<File> {
483483
private String cancelFileName;
484484
private boolean suppressCancel;
485485
private boolean cancelled;
@@ -500,7 +500,7 @@ protected List<File> find(File startDirectory) throws IOException {
500500

501501
/** Handles a directory end by adding the File to the result set. */
502502
@Override
503-
protected void handleDirectoryEnd(File directory, int depth, Collection results) throws IOException {
503+
protected void handleDirectoryEnd(File directory, int depth, Collection<File> results) throws IOException {
504504
results.add(directory);
505505
assertEquals(false, cancelled);
506506
if (cancelFileName.equals(directory.getName())) {
@@ -510,7 +510,7 @@ protected void handleDirectoryEnd(File directory, int depth, Collection results)
510510

511511
/** Handles a file by adding the File to the result set. */
512512
@Override
513-
protected void handleFile(File file, int depth, Collection results) throws IOException {
513+
protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
514514
results.add(file);
515515
assertEquals(false, cancelled);
516516
if (cancelFileName.equals(file.getName())) {
@@ -520,13 +520,13 @@ protected void handleFile(File file, int depth, Collection results) throws IOExc
520520

521521
/** Handles Cancelled. */
522522
@Override
523-
protected boolean handleIsCancelled(File file, int depth, Collection<?> results) throws IOException {
523+
protected boolean handleIsCancelled(File file, int depth, Collection<File> results) throws IOException {
524524
return cancelled;
525525
}
526526

527527
/** Handles Cancel. */
528528
@Override
529-
protected void handleCancelled(File startDirectory, Collection<?> results,
529+
protected void handleCancelled(File startDirectory, Collection<File> results,
530530
CancelException cancel) throws IOException {
531531
if (!suppressCancel) {
532532
super.handleCancelled(startDirectory, results, cancel);

src/test/org/apache/commons/io/FileUtilsTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ public void testMoveToDirectory_Errors() throws Exception {
16671667
/**
16681668
* DirectoryWalker implementation that recursively lists all files and directories.
16691669
*/
1670-
static class ListDirectoryWalker extends DirectoryWalker {
1670+
static class ListDirectoryWalker extends DirectoryWalker<File> {
16711671
ListDirectoryWalker() {
16721672
super();
16731673
}
@@ -1678,15 +1678,15 @@ List<File> list(File startDirectory) throws IOException {
16781678
}
16791679

16801680
@Override
1681-
protected void handleDirectoryStart(File directory, int depth, Collection results) throws IOException {
1681+
protected void handleDirectoryStart(File directory, int depth, Collection<File> results) throws IOException {
16821682
// Add all directories except the starting directory
16831683
if (depth > 0) {
16841684
results.add(directory);
16851685
}
16861686
}
16871687

16881688
@Override
1689-
protected void handleFile(File file, int depth, Collection results) throws IOException {
1689+
protected void handleFile(File file, int depth, Collection<File> results) throws IOException {
16901690
results.add(file);
16911691
}
16921692
}

0 commit comments

Comments
 (0)