Memoize additional FastFile properties

This commit is contained in:
Reinhard Pointner 2016-04-05 18:05:52 +00:00
parent fde24b657b
commit 80f13040b3
1 changed files with 16 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import java.io.IOException;
public class FastFile extends File {
private String name;
private Long length;
private Long lastModified;
private Boolean isDirectory;
@ -13,7 +14,9 @@ public class FastFile extends File {
private String[] list;
private File[] listFiles;
private String canonicalPath;
private File canonicalFile;
private File parentFile;
public FastFile(File file) {
super(file.getPath());
@ -23,6 +26,11 @@ public class FastFile extends File {
super(parent, child);
}
@Override
public String getName() {
return name != null ? name : (name = super.getName());
}
@Override
public long length() {
return length != null ? length : (length = super.length());
@ -49,8 +57,13 @@ public class FastFile extends File {
}
@Override
public String getCanonicalPath() throws IOException {
return canonicalPath != null ? canonicalPath : (canonicalPath = super.getCanonicalPath());
public File getCanonicalFile() throws IOException {
return canonicalFile != null ? canonicalFile : (canonicalFile = new FastFile(super.getCanonicalFile()));
}
@Override
public File getParentFile() {
return parentFile != null ? parentFile : (parentFile = new FastFile(super.getParentFile()));
}
@Override