- // Let's make the new backup file!! yay, got there at last!
- String latestBackupFilename = dir + File.separatorChar
- + BackupFilenameFilter.getBackupFilename(nextIndexNum, basename,
- suffix, digits, extension);
- File latestBackupFile = new File(latestBackupFilename);
- ret = ret && file.renameTo(latestBackupFile);
-
- return ret;
+ private TreeMap sortBackupFilesAsTreeMap(File[] backupFiles,
+ String basename)
+ {
+ // sort the backup files (based on integer found in the suffix) using a
+ // precomputed Hashmap for speed
+ Map<Integer, File> bfHashMap = new HashMap<>();
+ for (int i = 0; i < backupFiles.length; i++)
+ {
+ File f = backupFiles[i];
+ BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
+ digits);
+ bfHashMap.put(bfp.indexNum(), f);
+ }
+ TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
+ bfTreeMap.putAll(bfHashMap);
+ return bfTreeMap;