Refactor FastFile API

This commit is contained in:
Reinhard Pointner 2016-04-04 08:57:38 +00:00
parent 9fa587319f
commit cfd862c057
7 changed files with 8 additions and 29 deletions

View File

@ -240,7 +240,7 @@ public class ScriptShellMethods {
} }
public static FastFile memoize(File self) { public static FastFile memoize(File self) {
return new FastFile(self.getPath()); return new FastFile(self);
} }
public static File moveTo(File self, File destination) throws IOException { public static File moveTo(File self, File destination) throws IOException {

View File

@ -1,6 +1,5 @@
package net.filebot.media; package net.filebot.media;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
@ -1402,21 +1401,6 @@ public class MediaDetection {
} }
} }
public static List<File> getMediaUnits(File folder) {
if (folder.isHidden()) {
return emptyList();
}
if (folder.isDirectory() && !isDiskFolder(folder)) {
List<File> children = new ArrayList<File>();
for (File f : getChildren(folder)) {
children.addAll(getMediaUnits(f));
}
}
return singletonList(folder);
}
public static void warmupCachedResources() throws Exception { public static void warmupCachedResources() throws Exception {
// load filter data // load filter data
MediaDetection.getClutterFileFilter(); MediaDetection.getClutterFileFilter();

View File

@ -69,7 +69,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
} }
// use fast file to minimize system calls like length(), isDirectory(), isFile(), ... // use fast file to minimize system calls like length(), isDirectory(), isFile(), ...
FastFile root = FastFile.create(filter(files, FOLDERS))[0]; FastFile root = new FastFile(filter(files, FOLDERS).get(0));
// publish on EDT // publish on EDT
TreeNode[] node = { getTreeNode(root) }; TreeNode[] node = { getTreeNode(root) };

View File

@ -55,7 +55,8 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
// load files recursively by default // load files recursively by default
load(files, action != TransferAction.LINK, fileset); load(files, action != TransferAction.LINK, fileset);
publish(FastFile.create(fileset)); // use fast file to minimize system calls like length(), isDirectory(), isFile(), ...
publish(fileset.stream().map(FastFile::new).toArray(File[]::new));
} }
private void load(List<File> files, boolean recursive, Collection<File> sink) { private void load(List<File> files, boolean recursive, Collection<File> sink) {

View File

@ -2,7 +2,6 @@ package net.filebot.ui.rename;
import static java.awt.datatransfer.DataFlavor.*; import static java.awt.datatransfer.DataFlavor.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.ui.transfer.FileTransferable.*; import static net.filebot.ui.transfer.FileTransferable.*;
@ -98,7 +97,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
loadTorrentFiles(files, values); loadTorrentFiles(files, values);
} else { } else {
// load all files from the given folders recursively up do a depth of 32 // load all files from the given folders recursively up do a depth of 32
addAll(values, FastFile.create(listFiles(files))); listFiles(files).stream().map(FastFile::new).forEach(values::add);
} }
model.addAll(values); model.addAll(values);

View File

@ -182,7 +182,7 @@ class ChecksumTableModel extends AbstractTableModel {
cell.addPropertyChangeListener(progressListener); cell.addPropertyChangeListener(progressListener);
if (!checksumColumns.contains(cell.getRoot())) { if (!checksumColumns.contains(cell.getRoot())) {
checksumColumns.add(new FastFile(cell.getRoot().getPath())); checksumColumns.add(new FastFile(cell.getRoot()));
} }
} }

View File

@ -2,7 +2,6 @@ package net.filebot.util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
public class FastFile extends File { public class FastFile extends File {
@ -16,8 +15,8 @@ public class FastFile extends File {
private File[] listFiles; private File[] listFiles;
private String canonicalPath; private String canonicalPath;
public FastFile(String path) { public FastFile(File file) {
super(path); super(file.getPath());
} }
public FastFile(File parent, String child) { public FastFile(File parent, String child) {
@ -197,8 +196,4 @@ public class FastFile extends File {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public static FastFile[] create(Collection<File> files) {
return files.stream().map(f -> new FastFile(f.getPath())).toArray(FastFile[]::new);
}
} }