Memoize additional FastFile properties
This commit is contained in:
parent
fde24b657b
commit
80f13040b3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue