You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/10/19 12:49:04 UTC
(commons-text) branch master updated: Better internal names and comments
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-text.git
The following commit(s) were added to refs/heads/master by this push:
new 76df9e54 Better internal names and comments
76df9e54 is described below
commit 76df9e54399018163c8cd92bc1e407c7c4296612
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 19 08:48:58 2025 -0400
Better internal names and comments
---
.../text/lookup/AbstractPathFencedLookup.java | 4 +--
.../org/apache/commons/text/lookup/PathFence.java | 32 +++++++++++-----------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/commons/text/lookup/AbstractPathFencedLookup.java b/src/main/java/org/apache/commons/text/lookup/AbstractPathFencedLookup.java
index d077c177..b4fc4601 100644
--- a/src/main/java/org/apache/commons/text/lookup/AbstractPathFencedLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/AbstractPathFencedLookup.java
@@ -35,7 +35,7 @@ abstract class AbstractPathFencedLookup extends AbstractStringLookup {
* @param paths The fences guarding Path resolution.
*/
AbstractPathFencedLookup(final Path... paths) {
- this.fence = PathFence.builder().setPaths(paths).get();
+ this.fence = PathFence.builder().setRoots(paths).get();
}
/**
@@ -46,6 +46,6 @@ abstract class AbstractPathFencedLookup extends AbstractStringLookup {
* @throws IllegalArgumentException if the file name is not without our fence.
*/
protected Path getPath(final String fileName) {
- return fence.getPath(fileName);
+ return fence.apply(fileName);
}
}
diff --git a/src/main/java/org/apache/commons/text/lookup/PathFence.java b/src/main/java/org/apache/commons/text/lookup/PathFence.java
index 0428ef2f..95b9b615 100644
--- a/src/main/java/org/apache/commons/text/lookup/PathFence.java
+++ b/src/main/java/org/apache/commons/text/lookup/PathFence.java
@@ -26,7 +26,7 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
- * A Path fence guards Path resolution.
+ * A Path fence guards against using paths outside of a "fence" of made of root paths.
*
* Keep package-private.
*/
@@ -41,9 +41,14 @@ final class PathFence {
private static final Path[] EMPTY = {};
/**
- * A fence is made of Paths guarding Path resolution.
+ * A fence is made of root Paths.
*/
- private Path[] paths = EMPTY;
+ private Path[] roots = EMPTY;
+
+ @Override
+ public PathFence get() {
+ return new PathFence(this);
+ }
/**
* Sets the paths that delineate this fence.
@@ -51,15 +56,10 @@ final class PathFence {
* @param paths the paths that delineate this fence.
* @return {@code this} instance.
*/
- Builder setPaths(final Path... paths) {
- this.paths = paths != null ? paths.clone() : EMPTY;
+ Builder setRoots(final Path... paths) {
+ this.roots = paths != null ? paths.clone() : EMPTY;
return this;
}
-
- @Override
- public PathFence get() {
- return new PathFence(this);
- }
}
/**
@@ -74,7 +74,7 @@ final class PathFence {
/**
* A fence is made of Paths guarding Path resolution.
*/
- private final List<Path> paths;
+ private final List<Path> roots;
/**
* Constructs a new instance.
@@ -82,7 +82,7 @@ final class PathFence {
* @param builder A builder.
*/
private PathFence(final Builder builder) {
- this.paths = Arrays.stream(builder.paths).map(Path::toAbsolutePath).collect(Collectors.toList());
+ this.roots = Arrays.stream(builder.roots).map(Path::toAbsolutePath).collect(Collectors.toList());
}
/**
@@ -92,17 +92,17 @@ final class PathFence {
* @return a fenced Path.
* @throws IllegalArgumentException if the file name is not without our fence.
*/
- Path getPath(final String fileName) {
+ Path apply(final String fileName) {
final Path path = Paths.get(fileName);
- if (paths.isEmpty()) {
+ if (roots.isEmpty()) {
return path;
}
final Path pathAbs = path.normalize().toAbsolutePath();
- final Optional<Path> first = paths.stream().filter(pathAbs::startsWith).findFirst();
+ final Optional<Path> first = roots.stream().filter(pathAbs::startsWith).findFirst();
if (first.isPresent()) {
return path;
}
- throw new IllegalArgumentException(String.format("[%s] -> [%s] not in the fence %s", fileName, pathAbs, paths));
+ throw new IllegalArgumentException(String.format("[%s] -> [%s] not in the fence %s", fileName, pathAbs, roots));
}
}