Class LineExtensionBuilder
java.lang.Object
io.github.computerdaddyguy.jfiletreeprettyprinter.LineExtensionBuilder
A builder for constructing functions that provide optional line extensions
(such as comments or formatting markers) when pretty-printing file trees.
A LineExtensionBuilder allows you to add rules in the form of
Function objects that map a Path to an extension string.
When the resulting function is applied to a path, rules are evaluated
in insertion order, and the first non-null result is used.
nullmeans no extension (line is printed normally).- An empty string means "force line break" in compact directory chains.
- Any non-empty string is appended after the path (e.g. a comment).
Example usage:
var lineExtension = LineExtensionBuilder.newInstance()
.add(PathMatchers.hasName("README.md"), " // Project documentation")
.addLineBreak(PathMatchers.hasRelativePathMatchingGlob(root, "src/main/java"))
.build();
The returned Function<Path, String> can then be passed to
PrettyPrintOptions.withLineExtension(Function).- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionadd(PathMatcher pathMatcher, String extension) Adds a rule that appends the given extension when the matcher matches.Adds a custom line extension rule.addLineBreak(PathMatcher pathMatcher) Adds a rule that forces a line break (instead of appending text) whenever the given matcher matches.build()Builds the final function mapping aPathto an extension string.
-
Method Details
-
build
Builds the final function mapping aPathto an extension string.The function applies the registered rules in insertion order. The first rule returning a non-
nullvalue determines the extension. If none match, the function returnsnull.- Returns:
- a function mapping paths to extensions
-
add
Adds a custom line extension rule.The function should return either:
nullto indicate "no extension".- an empty string to force a line break.
- a non-empty string to append after the path.
- Parameters:
lineExtension- a function mapping paths to extensions (non-null)- Returns:
- this builder (for chaining)
- Throws:
NullPointerException- iflineExtensionis null
-
add
Adds a rule that appends the given extension when the matcher matches.If the matcher does not match, the rule returns
null.- Parameters:
pathMatcher- the matcher to test paths against (non-null)extension- the extension string to return when matched- Returns:
- this builder (for chaining)
- Throws:
NullPointerException- ifpathMatcheris null
-
addLineBreak
Adds a rule that forces a line break (instead of appending text) whenever the given matcher matches.- Parameters:
pathMatcher- the matcher to test paths against (non-null)- Returns:
- this builder (for chaining)
-