/** * Creates a CachedFile instance for each of the AbstractFile instances in the given array. */ private AbstractFile[] createCachedFiles(AbstractFile files[]) { int nbFiles = files.length; for(int i=0; i<nbFiles; i++) files[i] = new CachedFile(files[i], true); return files; }
@Override public AbstractFile getParent() { if(!getParentSet) { getParent = file.getParent(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances && getParent!=null) getParent = new CachedFile(getParent, true); getParentSet = true; } return getParent; }
@Override public AbstractFile getRoot() { if(!getRootSet) { getRoot = file.getRoot(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances) getRoot = new CachedFile(getRoot, true); getRootSet = true; } return getRoot; }
@Override public AbstractFile getCanonicalFile() { if(!getCanonicalFileSet) { getCanonicalFile = file.getCanonicalFile(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances) { // AbstractFile#getCanonicalFile() may return 'this' if the file is not a symlink. In that case, // no need to create a new CachedFile, simply use this one. if(getCanonicalFile==file) getCanonicalFile = this; else getCanonicalFile = new CachedFile(getCanonicalFile, true); } getCanonicalFileSet = true; } return getCanonicalFile; }
int nbFiles = children.length; this.currentFolder = (folder instanceof CachedFile)?folder:new CachedFile(folder, true); AbstractFile file; for(int i=0; i<nbFiles; i++) { file = new CachedFile(children[i], true);
/** * Creates a new FileJob without starting it, and with no associated ProgressDialog. * * @param mainFrame mainFrame this job has been triggered by * @param files files which are going to be processed */ public FileJob(MainFrame mainFrame, FileSet files) { this.mainFrame = mainFrame; this.files = files; this.nbFiles = files.size(); this.baseSourceFolder = files.getBaseFolder(); // Create CachedFile instances around the source files in order to cache the return value of frequently accessed // methods. This eliminates some I/O, at the (small) cost of a bit more CPU and memory. Recursion is enabled // so that children and parents of the files are also cached. // Note: When cached methods are called, they no longer reflect changes in the underlying files. In particular, // changes of size or date could potentially not be reflected when files are being processed but this should // not really present a risk. AbstractFile tempFile; for(int i=0; i<nbFiles; i++) { tempFile = files.elementAt(i); files.setElementAt((tempFile instanceof CachedFile)?tempFile:new CachedFile(tempFile, true), i); } if (this.baseSourceFolder!=null) this.baseSourceFolder = (getBaseSourceFolder() instanceof CachedFile)?getBaseSourceFolder():new CachedFile(getBaseSourceFolder(), true); this.jobProgress = new JobProgress(this); }