2626import java .util .stream .Collectors ;
2727
2828/**
29- * A Path fence guards Path resolution .
29+ * A Path fence guards against using paths outside of a "fence" of made of root paths .
3030 *
3131 * Keep package-private.
3232 */
@@ -41,25 +41,25 @@ static final class Builder implements Supplier<PathFence> {
4141 private static final Path [] EMPTY = {};
4242
4343 /**
44- * A fence is made of Paths guarding Path resolution .
44+ * A fence is made of root Paths .
4545 */
46- private Path [] paths = EMPTY ;
46+ private Path [] roots = EMPTY ;
47+
48+ @ Override
49+ public PathFence get () {
50+ return new PathFence (this );
51+ }
4752
4853 /**
4954 * Sets the paths that delineate this fence.
5055 *
5156 * @param paths the paths that delineate this fence.
5257 * @return {@code this} instance.
5358 */
54- Builder setPaths (final Path ... paths ) {
55- this .paths = paths != null ? paths .clone () : EMPTY ;
59+ Builder setRoots (final Path ... paths ) {
60+ this .roots = paths != null ? paths .clone () : EMPTY ;
5661 return this ;
5762 }
58-
59- @ Override
60- public PathFence get () {
61- return new PathFence (this );
62- }
6363 }
6464
6565 /**
@@ -74,15 +74,15 @@ static Builder builder() {
7474 /**
7575 * A fence is made of Paths guarding Path resolution.
7676 */
77- private final List <Path > paths ;
77+ private final List <Path > roots ;
7878
7979 /**
8080 * Constructs a new instance.
8181 *
8282 * @param builder A builder.
8383 */
8484 private PathFence (final Builder builder ) {
85- this .paths = Arrays .stream (builder .paths ).map (Path ::toAbsolutePath ).collect (Collectors .toList ());
85+ this .roots = Arrays .stream (builder .roots ).map (Path ::toAbsolutePath ).collect (Collectors .toList ());
8686 }
8787
8888 /**
@@ -92,17 +92,17 @@ private PathFence(final Builder builder) {
9292 * @return a fenced Path.
9393 * @throws IllegalArgumentException if the file name is not without our fence.
9494 */
95- Path getPath (final String fileName ) {
95+ Path apply (final String fileName ) {
9696 final Path path = Paths .get (fileName );
97- if (paths .isEmpty ()) {
97+ if (roots .isEmpty ()) {
9898 return path ;
9999 }
100100 final Path pathAbs = path .normalize ().toAbsolutePath ();
101- final Optional <Path > first = paths .stream ().filter (pathAbs ::startsWith ).findFirst ();
101+ final Optional <Path > first = roots .stream ().filter (pathAbs ::startsWith ).findFirst ();
102102 if (first .isPresent ()) {
103103 return path ;
104104 }
105- throw new IllegalArgumentException (String .format ("[%s] -> [%s] not in the fence %s" , fileName , pathAbs , paths ));
105+ throw new IllegalArgumentException (String .format ("[%s] -> [%s] not in the fence %s" , fileName , pathAbs , roots ));
106106 }
107107
108108}
0 commit comments