Improve general code quality

This commit is contained in:
2022-04-24 16:47:55 +02:00
parent a99abd5989
commit 10954f07a4
14 changed files with 75 additions and 118 deletions

View File

@@ -1,6 +1,5 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
import lombok.extern.log4j.Log4j2;
import java.io.File;
@@ -15,27 +14,17 @@ import java.util.stream.Stream;
@Log4j2
public class MkvFileCollector implements FileCollector {
private static final String[] fileExtensions = new String[]{".mkv", ".mka", ".mks", ".mk3d"};
@Override
public List<File> loadFiles(String path) {
File file = new File(path);
if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) {
return new ArrayList<>() {{
add(file);
}};
} else if (file.isDirectory()) {
try (Stream<Path> paths = Files.walk(Paths.get(path))) {
return paths
.filter(Files::isRegularFile)
.map(Path::toFile)
.filter(f -> f.getAbsolutePath().endsWith(".mkv"))
.filter(f -> Config.getInstance().getIncludePattern().matcher(f.getName()).matches())
.collect(Collectors.toList());
} catch (IOException e) {
log.error("Couldn't find file or directory!", e);
return new ArrayList<>();
}
} else {
try (Stream<Path> paths = Files.walk(Paths.get(path))) {
return paths.filter(Files::isRegularFile)
.map(Path::toFile)
.filter(file -> FileFilter.accept(file, fileExtensions))
.collect(Collectors.toList());
} catch (IOException e) {
log.error("Couldn't find file or directory!", e);
return new ArrayList<>();
}
}