mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 16:09:18 +01:00
[NUSTitle] Improve getFSTEntriesByRegEx
This commit is contained in:
parent
89fbc830f1
commit
9bc418357e
@ -100,19 +100,35 @@ public class NUSTitle {
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx) {
|
||||
List<FSTEntry> files = getAllFSTEntriesFlat();
|
||||
return getFSTEntriesByRegEx(regEx, FST.getRoot());
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, FSTEntry entry) {
|
||||
return getFSTEntriesByRegEx(regEx, entry, true);
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, boolean onlyInPackage) {
|
||||
return getFSTEntriesByRegEx(regEx, FST.getRoot(), onlyInPackage);
|
||||
}
|
||||
|
||||
public List<FSTEntry> getFSTEntriesByRegEx(String regEx, FSTEntry entry, boolean allowNotInPackage) {
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
return getFSTEntriesByRegExStream(p, entry, allowNotInPackage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<FSTEntry> result = new ArrayList<>();
|
||||
|
||||
for (FSTEntry f : files) {
|
||||
String match = f.getFullPath().replace(File.separator, "/");
|
||||
Matcher m = p.matcher(match);
|
||||
if (m.matches()) {
|
||||
result.add(f);
|
||||
private Stream<FSTEntry> getFSTEntriesByRegExStream(Pattern p, FSTEntry entry, boolean allowNotInPackage) {
|
||||
return entry.getChildren().stream()//
|
||||
.filter(e -> allowNotInPackage || !e.isNotInPackage()) //
|
||||
.flatMap(e -> {
|
||||
if (!e.isDir()) {
|
||||
if (p.matcher(entry.getFullPath().replace("/", File.separator)).matches()) {
|
||||
return Stream.of(entry);
|
||||
} else {
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return getFSTEntriesByRegExStream(p, e, allowNotInPackage);
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<FSTEntry> getFileEntryDir(String string) {
|
||||
|
Loading…
Reference in New Issue
Block a user