6060 */
6161public class AccumulatorPathVisitor extends CountingPathVisitor {
6262
63+ /**
64+ * Builds instances of {@link AccumulatorPathVisitor}.
65+ *
66+ * @since 2.18.0
67+ */
68+ public static class Builder extends AbstractBuilder <AccumulatorPathVisitor , Builder > {
69+ @ Override
70+ public AccumulatorPathVisitor get () {
71+ return new AccumulatorPathVisitor (this );
72+ }
73+
74+ }
75+
76+ /**
77+ * Builds instances of {@link AccumulatorPathVisitor}.
78+ *
79+ * @return a new builder.
80+ * @since 2.18.0
81+ */
82+ public static Builder builder () {
83+ return new Builder ();
84+ }
85+
6386 /**
6487 * Constructs a new instance configured with a BigInteger {@link PathCounters}.
6588 *
6689 * @return a new instance configured with a BigInteger {@link PathCounters}.
90+ * @see #builder()
91+ * @see Builder
6792 */
6893 public static AccumulatorPathVisitor withBigIntegerCounters () {
69- return new AccumulatorPathVisitor ( Counters .bigIntegerPathCounters ());
94+ return builder (). setPathCounters ( Counters .bigIntegerPathCounters ()). get ( );
7095 }
7196
7297 /**
@@ -75,20 +100,23 @@ public static AccumulatorPathVisitor withBigIntegerCounters() {
75100 * @param fileFilter Filters files to accumulate and count.
76101 * @param dirFilter Filters directories to accumulate and count.
77102 * @return a new instance configured with a long {@link PathCounters}.
103+ * @see #builder()
104+ * @see Builder
78105 * @since 2.9.0
79106 */
80- public static AccumulatorPathVisitor withBigIntegerCounters (final PathFilter fileFilter ,
81- final PathFilter dirFilter ) {
82- return new AccumulatorPathVisitor (Counters .bigIntegerPathCounters (), fileFilter , dirFilter );
107+ public static AccumulatorPathVisitor withBigIntegerCounters (final PathFilter fileFilter , final PathFilter dirFilter ) {
108+ return builder ().setPathCounters (Counters .bigIntegerPathCounters ()).setFileFilter (fileFilter ).setDirectoryFilter (dirFilter ).get ();
83109 }
84110
85111 /**
86112 * Constructs a new instance configured with a long {@link PathCounters}.
87113 *
88114 * @return a new instance configured with a long {@link PathCounters}.
115+ * @see #builder()
116+ * @see Builder
89117 */
90118 public static AccumulatorPathVisitor withLongCounters () {
91- return new AccumulatorPathVisitor ( Counters .longPathCounters ());
119+ return builder (). setPathCounters ( Counters .longPathCounters ()). get ( );
92120 }
93121
94122 /**
@@ -97,30 +125,40 @@ public static AccumulatorPathVisitor withLongCounters() {
97125 * @param fileFilter Filters files to accumulate and count.
98126 * @param dirFilter Filters directories to accumulate and count.
99127 * @return a new instance configured with a long {@link PathCounters}.
128+ * @see #builder()
129+ * @see Builder
100130 * @since 2.9.0
101131 */
102132 public static AccumulatorPathVisitor withLongCounters (final PathFilter fileFilter , final PathFilter dirFilter ) {
103- return new AccumulatorPathVisitor ( Counters .longPathCounters (), fileFilter , dirFilter );
133+ return builder (). setPathCounters ( Counters .longPathCounters ()). setFileFilter ( fileFilter ). setDirectoryFilter ( dirFilter ). get ( );
104134 }
105135
106136 private final List <Path > dirList = new ArrayList <>();
107137
108138 private final List <Path > fileList = new ArrayList <>();
109139
110140 /**
111- * Constructs a new instance.
141+ * Constructs a new instance with a noop path counter .
112142 *
113143 * @since 2.9.0
144+ * @deprecated Use {@link #builder()}.
114145 */
146+ @ Deprecated
115147 public AccumulatorPathVisitor () {
116148 super (Counters .noopPathCounters ());
117149 }
118150
151+ private AccumulatorPathVisitor (final Builder builder ) {
152+ super (builder );
153+ }
154+
119155 /**
120156 * Constructs a new instance that counts file system elements.
121157 *
122158 * @param pathCounter How to count path visits.
159+ * @deprecated Use {@link #builder()}.
123160 */
161+ @ Deprecated
124162 public AccumulatorPathVisitor (final PathCounters pathCounter ) {
125163 super (pathCounter );
126164 }
@@ -132,7 +170,9 @@ public AccumulatorPathVisitor(final PathCounters pathCounter) {
132170 * @param fileFilter Filters which files to count.
133171 * @param dirFilter Filters which directories to count.
134172 * @since 2.9.0
173+ * @deprecated Use {@link #builder()}.
135174 */
175+ @ Deprecated
136176 public AccumulatorPathVisitor (final PathCounters pathCounter , final PathFilter fileFilter , final PathFilter dirFilter ) {
137177 super (pathCounter , fileFilter , dirFilter );
138178 }
@@ -145,7 +185,9 @@ public AccumulatorPathVisitor(final PathCounters pathCounter, final PathFilter f
145185 * @param dirFilter Filters which directories to count.
146186 * @param visitFileFailed Called on {@link #visitFileFailed(Path, IOException)}.
147187 * @since 2.12.0
188+ * @deprecated Use {@link #builder()}.
148189 */
190+ @ Deprecated
149191 public AccumulatorPathVisitor (final PathCounters pathCounter , final PathFilter fileFilter , final PathFilter dirFilter ,
150192 final IOBiFunction <Path , IOException , FileVisitResult > visitFileFailed ) {
151193 super (pathCounter , fileFilter , dirFilter , visitFileFailed );
0 commit comments