This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new 58d9d82 Implement hashCode() and equals() on path counters. 58d9d82 is described below commit 58d9d82879b1f4e24345cc825e70b7059791cf5e Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Mon Nov 25 20:42:29 2019 -0500 Implement hashCode() and equals() on path counters. --- .../org/apache/commons/io/file/CountingPathVisitor.java | 17 +++++++++++++++++ .../apache/commons/io/file/CountingPathVisitorTest.java | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/org/apache/commons/io/file/CountingPathVisitor.java b/src/main/java/org/apache/commons/io/file/CountingPathVisitor.java index 987863b..cdda3b2 100644 --- a/src/main/java/org/apache/commons/io/file/CountingPathVisitor.java +++ b/src/main/java/org/apache/commons/io/file/CountingPathVisitor.java @@ -65,6 +65,18 @@ public class CountingPathVisitor extends SimplePathVisitor { this.pathCounters = Objects.requireNonNull(pathCounter, "pathCounter"); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof CountingPathVisitor)) { + return false; + } + CountingPathVisitor other = (CountingPathVisitor) obj; + return Objects.equals(pathCounters, other.pathCounters); + } + /** * Gets the visitation counts. * @@ -75,6 +87,11 @@ public class CountingPathVisitor extends SimplePathVisitor { } @Override + public int hashCode() { + return Objects.hash(pathCounters); + } + + @Override public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException { pathCounters.getDirectoryCounter().increment(); return FileVisitResult.CONTINUE; diff --git a/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java b/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java index afdd998..f8078b6 100644 --- a/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java +++ b/src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -37,6 +38,7 @@ public class CountingPathVisitorTest extends TestArguments { @ParameterizedTest @MethodSource("countingPathVisitors") public void testCountEmptyFolder(final CountingPathVisitor visitor) throws IOException { + checkZeroCounts(visitor); final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName()); try { assertCounts(1, 0, 0, PathUtils.visitFileTree(visitor, tempDir)); @@ -51,6 +53,7 @@ public class CountingPathVisitorTest extends TestArguments { @ParameterizedTest @MethodSource("countingPathVisitors") public void testCountFolders1FileSize0(final CountingPathVisitor visitor) throws IOException { + checkZeroCounts(visitor); assertCounts(1, 1, 0, PathUtils.visitFileTree(visitor, "src/test/resources/org/apache/commons/io/dirs-1-file-size-0")); } @@ -61,6 +64,7 @@ public class CountingPathVisitorTest extends TestArguments { @ParameterizedTest @MethodSource("countingPathVisitors") public void testCountFolders1FileSize1(final CountingPathVisitor visitor) throws IOException { + checkZeroCounts(visitor); assertCounts(1, 1, 1, PathUtils.visitFileTree(visitor, "src/test/resources/org/apache/commons/io/dirs-1-file-size-1")); } @@ -71,10 +75,16 @@ public class CountingPathVisitorTest extends TestArguments { @ParameterizedTest @MethodSource("countingPathVisitors") public void testCountFolders2FileSize2(final CountingPathVisitor visitor) throws IOException { + checkZeroCounts(visitor); assertCounts(3, 2, 2, PathUtils.visitFileTree(visitor, "src/test/resources/org/apache/commons/io/dirs-2-file-size-2")); } + private void checkZeroCounts(final CountingPathVisitor visitor) { + Assertions.assertEquals(CountingPathVisitor.withLongCounters(), visitor); + Assertions.assertEquals(CountingPathVisitor.withBigIntegerCounters(), visitor); + } + @ParameterizedTest @MethodSource("countingPathVisitors") void testToString(final CountingPathVisitor visitor) {