public class AccumulatorPathVisitor extends CountingPathVisitor
Use with care on large file trees as each visited Path element is remembered.
Path dir = PathUtils.current(); // We are interested in files older than one day Instant cutoff = Instant.now().minus(Duration.ofDays(1)); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
| Modifier and Type | Class and Description |
|---|---|
static class |
AccumulatorPathVisitor.Builder
Builds instances of
AccumulatorPathVisitor. |
CountingPathVisitor.AbstractBuilder<T,B extends CountingPathVisitor.AbstractBuilder<T,B>>EMPTY_STRING_ARRAY| Modifier and Type | Method and Description |
|---|---|
static AccumulatorPathVisitor.Builder |
builder()
Builds instances of
AccumulatorPathVisitor. |
boolean |
equals(Object obj) |
List<Path> |
getDirList()
Gets a copy of the list of visited directories.
|
List<Path> |
getFileList()
Gets a copy of the list of visited files.
|
int |
hashCode() |
List<Path> |
relativizeDirectories(Path parent,
boolean sort,
Comparator<? super Path> comparator)
Relativizes each directory path with
Path.relativize(Path) against the given parent, optionally
sorting the result. |
List<Path> |
relativizeFiles(Path parent,
boolean sort,
Comparator<? super Path> comparator)
Relativizes each file path with
Path.relativize(Path) against the given parent, optionally
sorting the result. |
protected void |
updateDirCounter(Path dir,
IOException exc)
Updates the counter for visiting the given directory.
|
protected void |
updateFileCounters(Path file,
BasicFileAttributes attributes)
Updates the counters for visiting the given file.
|
static AccumulatorPathVisitor |
withBigIntegerCounters()
Constructs a new instance configured with a BigInteger
Counters.PathCounters. |
static AccumulatorPathVisitor |
withBigIntegerCounters(PathFilter fileFilter,
PathFilter dirFilter)
Constructs a new instance configured with a BigInteger
Counters.PathCounters. |
static AccumulatorPathVisitor |
withLongCounters()
Constructs a new instance configured with a long
Counters.PathCounters. |
static AccumulatorPathVisitor |
withLongCounters(PathFilter fileFilter,
PathFilter dirFilter)
Constructs a new instance configured with a long
Counters.PathCounters. |
accept, defaultDirectoryFilter, defaultDirectoryTransformer, defaultFileFilter, defaultPathCounters, getPathCounters, postVisitDirectory, preVisitDirectory, toString, visitFilevisitFileFailedpublic static AccumulatorPathVisitor.Builder builder()
AccumulatorPathVisitor.public boolean equals(Object obj)
equals in class CountingPathVisitorpublic List<Path> getDirList()
public List<Path> getFileList()
public int hashCode()
hashCode in class CountingPathVisitorpublic List<Path> relativizeDirectories(Path parent, boolean sort, Comparator<? super Path> comparator)
Path.relativize(Path) against the given parent, optionally
sorting the result.parent - A parent pathsort - Whether to sortcomparator - How to sort, null uses default sorting.public List<Path> relativizeFiles(Path parent, boolean sort, Comparator<? super Path> comparator)
Path.relativize(Path) against the given parent, optionally
sorting the result.parent - A parent pathsort - Whether to sortcomparator - How to sort, null uses default sorting.protected void updateDirCounter(Path dir, IOException exc)
CountingPathVisitorupdateDirCounter in class CountingPathVisitordir - the visited directory.exc - Encountered exception.protected void updateFileCounters(Path file, BasicFileAttributes attributes)
CountingPathVisitorupdateFileCounters in class CountingPathVisitorfile - the visited file.attributes - the visited file attributes.public static AccumulatorPathVisitor withBigIntegerCounters()
Counters.PathCounters.Counters.PathCounters.builder(),
AccumulatorPathVisitor.Builderpublic static AccumulatorPathVisitor withBigIntegerCounters(PathFilter fileFilter, PathFilter dirFilter)
Counters.PathCounters.fileFilter - Filters files to accumulate and count.dirFilter - Filters directories to accumulate and count.Counters.PathCounters.builder(),
AccumulatorPathVisitor.Builderpublic static AccumulatorPathVisitor withLongCounters()
Counters.PathCounters.Counters.PathCounters.builder(),
AccumulatorPathVisitor.Builderpublic static AccumulatorPathVisitor withLongCounters(PathFilter fileFilter, PathFilter dirFilter)
Counters.PathCounters.fileFilter - Filters files to accumulate and count.dirFilter - Filters directories to accumulate and count.Counters.PathCounters.builder(),
AccumulatorPathVisitor.Builder