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 dir Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk dir tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList());
Constructor and Description |
---|
AccumulatorPathVisitor()
Constructs a new instance.
|
AccumulatorPathVisitor(Counters.PathCounters pathCounter)
Constructs a new instance that counts file system elements.
|
AccumulatorPathVisitor(Counters.PathCounters pathCounter,
PathFilter fileFilter,
PathFilter dirFilter)
Constructs a new instance.
|
AccumulatorPathVisitor(Counters.PathCounters pathCounter,
PathFilter fileFilter,
PathFilter dirFilter,
IOBiFunction<java.nio.file.Path,java.io.IOException,java.nio.file.FileVisitResult> visitFileFailed)
Constructs a new instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
java.util.List<java.nio.file.Path> |
getDirList()
Gets the list of visited directories.
|
java.util.List<java.nio.file.Path> |
getFileList()
Gets the list of visited files.
|
int |
hashCode() |
java.util.List<java.nio.file.Path> |
relativizeDirectories(java.nio.file.Path parent,
boolean sort,
java.util.Comparator<? super java.nio.file.Path> comparator)
Relativizes each directory path with
Path.relativize(Path) against the given parent , optionally
sorting the result. |
java.util.List<java.nio.file.Path> |
relativizeFiles(java.nio.file.Path parent,
boolean sort,
java.util.Comparator<? super java.nio.file.Path> comparator)
Relativizes each file path with
Path.relativize(Path) against the given parent , optionally
sorting the result. |
static AccumulatorPathVisitor |
withBigIntegerCounters()
Creates a new instance configured with a BigInteger
Counters.PathCounters . |
static AccumulatorPathVisitor |
withBigIntegerCounters(PathFilter fileFilter,
PathFilter dirFilter)
Creates a new instance configured with a BigInteger
Counters.PathCounters . |
static AccumulatorPathVisitor |
withLongCounters()
Creates a new instance configured with a long
Counters.PathCounters . |
static AccumulatorPathVisitor |
withLongCounters(PathFilter fileFilter,
PathFilter dirFilter)
Creates a new instance configured with a long
Counters.PathCounters . |
getPathCounters, postVisitDirectory, preVisitDirectory, toString, visitFile
visitFileFailed
public AccumulatorPathVisitor()
public AccumulatorPathVisitor(Counters.PathCounters pathCounter)
pathCounter
- How to count path visits.public AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter)
pathCounter
- How to count path visits.fileFilter
- Filters which files to count.dirFilter
- Filters which directories to count.public AccumulatorPathVisitor(Counters.PathCounters pathCounter, PathFilter fileFilter, PathFilter dirFilter, IOBiFunction<java.nio.file.Path,java.io.IOException,java.nio.file.FileVisitResult> visitFileFailed)
pathCounter
- How to count path visits.fileFilter
- Filters which files to count.dirFilter
- Filters which directories to count.visitFileFailed
- Called on SimplePathVisitor.visitFileFailed(Path, IOException)
.public static AccumulatorPathVisitor withBigIntegerCounters()
Counters.PathCounters
.Counters.PathCounters
.public 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
.public static AccumulatorPathVisitor withLongCounters()
Counters.PathCounters
.Counters.PathCounters
.public 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
.public boolean equals(java.lang.Object obj)
equals
in class CountingPathVisitor
public java.util.List<java.nio.file.Path> getDirList()
public java.util.List<java.nio.file.Path> getFileList()
public int hashCode()
hashCode
in class CountingPathVisitor
public java.util.List<java.nio.file.Path> relativizeDirectories(java.nio.file.Path parent, boolean sort, java.util.Comparator<? super java.nio.file.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 java.util.List<java.nio.file.Path> relativizeFiles(java.nio.file.Path parent, boolean sort, java.util.Comparator<? super java.nio.file.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.Copyright © 2010 - 2023 Adobe. All Rights Reserved