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 {
|
public class FastFile extends File {
|
||||||
|
|
||||||
|
private String name;
|
||||||
private Long length;
|
private Long length;
|
||||||
private Long lastModified;
|
private Long lastModified;
|
||||||
private Boolean isDirectory;
|
private Boolean isDirectory;
|
||||||
|
@ -13,7 +14,9 @@ public class FastFile extends File {
|
||||||
|
|
||||||
private String[] list;
|
private String[] list;
|
||||||
private File[] listFiles;
|
private File[] listFiles;
|
||||||
private String canonicalPath;
|
|
||||||
|
private File canonicalFile;
|
||||||
|
private File parentFile;
|
||||||
|
|
||||||
public FastFile(File file) {
|
public FastFile(File file) {
|
||||||
super(file.getPath());
|
super(file.getPath());
|
||||||
|
@ -23,6 +26,11 @@ public class FastFile extends File {
|
||||||
super(parent, child);
|
super(parent, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name != null ? name : (name = super.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long length() {
|
public long length() {
|
||||||
return length != null ? length : (length = super.length());
|
return length != null ? length : (length = super.length());
|
||||||
|
@ -49,8 +57,13 @@ public class FastFile extends File {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCanonicalPath() throws IOException {
|
public File getCanonicalFile() throws IOException {
|
||||||
return canonicalPath != null ? canonicalPath : (canonicalPath = super.getCanonicalPath());
|
return canonicalFile != null ? canonicalFile : (canonicalFile = new FastFile(super.getCanonicalFile()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getParentFile() {
|
||||||
|
return parentFile != null ? parentFile : (parentFile = new FastFile(super.getParentFile()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue