Skip to content

Commit 56d79c4

Browse files
PathPredicates: added "hasNameStartingWith"
1 parent 92d051a commit 56d79c4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
## [0.0.5] - Unreleased
1010

1111
### Added
12-
- New path predicates: `hasParentMatching`, `hasAncestorMatching`, `hasDirectChildMatching`, `hasDescendantMatching`, `hasSiblingMatching`, `hasFullPathMatchingGlob`, `hasFullPathMatching`, `hasNameMatchingGlob`
12+
- New path predicates: `hasParentMatching`, `hasAncestorMatching`, `hasDirectChildMatching`, `hasDescendantMatching`, `hasSiblingMatching`, `hasFullPathMatchingGlob`, `hasFullPathMatching`, `hasNameMatchingGlob`, `hasNameStartingWith`
1313

1414
### Changed
15-
- `PathUtils` removed, `PathPredicates`rework
15+
- `PathUtils` removed, `PathPredicates` rework
1616

1717
---
1818
## [0.0.4] - 2025-09-27

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/PathPredicates.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ public static boolean hasNameMatchingGlob(Path path, String glob) {
158158
return hasFullPathMatchingGlob(path.getFileName(), glob);
159159
}
160160

161+
/**
162+
* Tests whether the given path's file name starts with the specified suffix.
163+
*
164+
* @param path the path to test
165+
* @param prefix the prefix to test (e.g. ".", "analysis-")
166+
*
167+
* @return {@code true} if the file name starts with the given prefix
168+
*
169+
* @throws NullPointerException if {@code path} or {@code prefix} is {@code null}
170+
*/
171+
public static boolean hasNameStartingWith(Path path, String prefix) {
172+
Objects.requireNonNull(path, "path is null");
173+
Objects.requireNonNull(prefix, "prefix is null");
174+
return path.getFileName().toString().startsWith(prefix);
175+
}
176+
161177
/**
162178
* Tests whether the given path's file name ends with the specified suffix.
163179
*

0 commit comments

Comments
 (0)