Minor optimizations

This commit is contained in:
Reinhard Pointner 2016-10-07 00:56:52 +08:00
parent 14e87227bc
commit 297a69be33
2 changed files with 27 additions and 31 deletions

View File

@ -513,14 +513,7 @@ public class ReleaseInfo {
@Override
public boolean accept(File dir) {
if (dir.isDirectory()) {
for (File f : getChildren(dir)) {
if (entryPattern.matcher(f.getName()).matches()) {
return true;
}
}
}
return false;
return getChildren(dir, f -> entryPattern.matcher(f.getName()).matches()).size() > 0;
}
}

View File

@ -1,6 +1,9 @@
package net.filebot.util;
import static java.util.Arrays.*;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
public class FastFile extends File {
@ -12,6 +15,9 @@ public class FastFile extends File {
private Boolean isFile;
private Boolean isHidden;
private Long totalSpace;
private Long freeSpace;
private String[] list;
private File[] listFiles;
@ -86,13 +92,12 @@ public class FastFile extends File {
return listFiles;
}
String[] names = list();
File[] files = new File[names.length];
for (int i = 0; i < names.length; i++) {
files[i] = new FastFile(this, names[i]);
}
return (listFiles = stream(list()).map(s -> new FastFile(this, s)).toArray(File[]::new));
}
return (listFiles = files);
@Override
public File[] listFiles(FileFilter filter) {
return stream(listFiles()).filter(filter::accept).toArray(File[]::new);
}
@Override
@ -115,6 +120,21 @@ public class FastFile extends File {
return false;
}
@Override
public long getTotalSpace() {
return totalSpace != null ? totalSpace : (totalSpace = super.getTotalSpace());
}
@Override
public long getFreeSpace() {
return freeSpace != null ? freeSpace : (freeSpace = super.getFreeSpace());
}
@Override
public long getUsableSpace() {
return freeSpace != null ? freeSpace : (freeSpace = super.getFreeSpace());
}
@Override
public boolean createNewFile() throws IOException {
throw new UnsupportedOperationException();
@ -192,23 +212,6 @@ public class FastFile extends File {
}
@Override
public long getTotalSpace() {
throw new UnsupportedOperationException();
}
@Override
public long getFreeSpace() {
throw new UnsupportedOperationException();
}
@Override
public long getUsableSpace() {
throw new UnsupportedOperationException();
}
public static FastFile get(File f) {
return f == null ? null : new FastFile(f);
}