Skip to content

Commit 76df9e5

Browse files
committed
Better internal names and comments
1 parent 12b1e6a commit 76df9e5

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/main/java/org/apache/commons/text/lookup/AbstractPathFencedLookup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class AbstractPathFencedLookup extends AbstractStringLookup {
3535
* @param paths The fences guarding Path resolution.
3636
*/
3737
AbstractPathFencedLookup(final Path... paths) {
38-
this.fence = PathFence.builder().setPaths(paths).get();
38+
this.fence = PathFence.builder().setRoots(paths).get();
3939
}
4040

4141
/**
@@ -46,6 +46,6 @@ abstract class AbstractPathFencedLookup extends AbstractStringLookup {
4646
* @throws IllegalArgumentException if the file name is not without our fence.
4747
*/
4848
protected Path getPath(final String fileName) {
49-
return fence.getPath(fileName);
49+
return fence.apply(fileName);
5050
}
5151
}

src/main/java/org/apache/commons/text/lookup/PathFence.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import 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

Comments
 (0)