import java.io.File;
import java.io.IOException;
import java.util.Arrays;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
import java.util.TreeMap;
/*
public static final String REVERSE_ORDER = NS + "_REVERSE_ORDER";
- public static final String CONFIRM_DELETE_OLD = NS + "_CONFIRM_DELETE_OLD";
+ public static final String CONFIRM_DELETE_OLD = NS
+ + "_CONFIRM_DELETE_OLD";
private static final String DEFAULT_TEMP_FILE = "jalview_temp_file_" + NS;
this(file, ".v" + NUM_PLACEHOLDER, false, 4, 3, false);
}
- public BackupFiles(File file,
- String defaultSuffix, boolean defaultNoMax, int defaultMax,
- int defaultDigits,
- boolean defaultReverseOrder)
+ public BackupFiles(File file, String defaultSuffix, boolean defaultNoMax,
+ int defaultMax, int defaultDigits, boolean defaultReverseOrder)
{
classInit();
this.file = file;
return tempFile.renameTo(file);
}
-
// roll the backupfiles
public boolean rollBackupFiles()
{
// Create/move backups up one
File[] oldFilesToDelete = null;
-
+
// find existing backup files
BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
digits);
File[] backupFiles = dirFile.listFiles(bff);
int nextIndexNum = 0;
String confirmDeleteExtraInfo = null;
-
+
if (backupFiles.length == 0)
{
// No other backup files. Just need to move existing file to backupfile_1
}
else
{
- TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(backupFiles, basename);
+ TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
+ backupFiles, basename);
if (reverseOrder)
{
// if (m == 0 && backupfile_n.exists())
if ((!noMax) && n == tempMax && backupfile_n.exists())
{
- // move the largest (max) rolled file to a temp file and add to the delete list
+ // move the largest (max) rolled file to a temp file and add to the
+ // delete list
try
{
File temp = File.createTempFile(backupfilename, TEMP_FILE_EXT,
- dirFile);
+ dirFile);
backupfile_n.renameTo(temp);
oldFilesToDelete = new File[] { temp };
// version style numbering (with earliest file deletion if max files
// reached)
-
bfTreeMap.values().toArray(backupFiles);
// noMax == true means keep all backup files
return ret;
}
- private void deleteOldFiles(File[] oldFilesToDelete, String confirmDeleteExtraInfo) {
+ private void deleteOldFiles(File[] oldFilesToDelete,
+ String confirmDeleteExtraInfo)
+ {
if (oldFilesToDelete != null && oldFilesToDelete.length > 0)
{
// delete old backup/version files
}
}
- 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;
+ 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;
}
public boolean rollBackupsAndRenameTempFile()
{
boolean write = this.getWriteSuccess();
-
+
boolean roll = false;
- if (write) {
+ if (write)
+ {
roll = this.rollBackupFiles();
- } else {
+ }
+ else
+ {
return false;
}
-
+
/*
* Not sure that this confirmation is desirable. By this stage the new file is
* already written successfully, but something (e.g. disk full) has happened while
int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop,
MessageManager.getString(
"label.backupfiles_confirm_save_file_backupfiles_roll_wrong"),
- MessageManager.getString("label.backupfiles_confirm_save_file"),
+ MessageManager
+ .getString("label.backupfiles_confirm_save_file"),
JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
if (confirm == JvOptionPane.YES_OPTION)
}
public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
- String fileName,
- String suffix, int digits)
+ String fileName, String suffix, int digits)
{
File[] backupFiles = null;
String filename = file.getName();
String basename = filename;
-
+
// find existing backup files
- BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix, digits);
+ BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
+ digits);
backupFiles = dirFile.listFiles(bff); // is clone needed?
-
+
// sort the backup files (based on integer found in the suffix) using a
// precomputed Hashmap for speed
Map<Integer, File> bfHashMap = new HashMap<>();
return bfTreeMap;
}
-
}
-