Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: Make FileTree predicate methods public since they can be useful #5259

Merged
merged 1 commit into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions aQute.libg/src/aQute/lib/io/FileTree.java
@@ -1,5 +1,7 @@
package aQute.lib.io;

import static java.util.Objects.requireNonNull;

import java.io.File;
import java.nio.file.Path;
import java.text.CollationKey;
Expand Down Expand Up @@ -103,7 +105,16 @@ public List<File> getFiles(File baseDir, List<String> defaultIncludes) {
return getFiles(baseDir, files.isEmpty() ? paths.matches(defaultIncludes) : paths.matches());
}

private List<File> getFiles(File baseDir, Predicate<String> matches) {
/**
* Return a list of files using the specified baseDir and the specified
* relative path matching predicate.
*
* @param baseDir The base directory for locating files.
* @param matches The path matching predicate. The predicate only matches
* against the relative path from the specified baseDir.
* @return A list of files.
*/
public List<File> getFiles(File baseDir, Predicate<String> matches) {
ArrayList<File> result = new ArrayList<>();
new FileTreeSpliterator(baseDir, matches, files).forEachRemaining(result::add);
result.trimToSize();
Expand Down Expand Up @@ -136,7 +147,16 @@ public Stream<File> stream(File baseDir, List<String> defaultIncludes) {
return stream(baseDir, files.isEmpty() ? paths.matches(defaultIncludes) : paths.matches());
}

private Stream<File> stream(File baseDir, Predicate<String> matches) {
/**
* Return a stream of files using the specified baseDir and the specified
* relative path matching predicate.
*
* @param baseDir The base directory for locating files.
* @param matches The path matching predicate. The predicate only matches
* against the relative path from the specified baseDir.
* @return A stream of files.
*/
public Stream<File> stream(File baseDir, Predicate<String> matches) {
return StreamSupport.stream(new FileTreeSpliterator(baseDir, matches, files), false);
}

Expand All @@ -154,7 +174,7 @@ final static class FileTreeSpliterator extends AbstractSpliterator<File> {
super(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.NONNULL);
basePath = baseDir.toPath();
this.matches = matches;
this.matches = requireNonNull(matches);
List<File> copy = new ArrayList<>(files); // mutable copy
this.files = copy;
extra = copy.spliterator(); // late-binding
Expand Down
2 changes: 1 addition & 1 deletion aQute.libg/src/aQute/lib/io/package-info.java
@@ -1,4 +1,4 @@
@Version("4.2.0")
@Version("4.3.0")
package aQute.lib.io;

import org.osgi.annotation.versioning.Version;