JAL-3141 Reformatted code in eclipse
[jalview.git] / src / jalview / io / BackupFiles.java
index aafe8f2..e913fbc 100644 (file)
@@ -8,8 +8,8 @@ import jalview.util.MessageManager;
 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;
 
 /*
@@ -44,7 +44,8 @@ public class BackupFiles
 
   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;
 
@@ -95,10 +96,8 @@ public class BackupFiles
     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;
@@ -205,7 +204,6 @@ public class BackupFiles
     return tempFile.renameTo(file);
   }
 
-
   // roll the backupfiles
   public boolean rollBackupFiles()
   {
@@ -238,14 +236,14 @@ public class BackupFiles
     // 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
@@ -253,7 +251,8 @@ public class BackupFiles
     }
     else
     {
-      TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(backupFiles, basename);
+      TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
+              backupFiles, basename);
 
       if (reverseOrder)
       {
@@ -294,11 +293,12 @@ public class BackupFiles
           // 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 };
@@ -330,7 +330,6 @@ public class BackupFiles
         // version style numbering (with earliest file deletion if max files
         // reached)
 
-
         bfTreeMap.values().toArray(backupFiles);
 
         // noMax == true means keep all backup files
@@ -361,7 +360,9 @@ public class BackupFiles
     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
@@ -411,32 +412,38 @@ public class BackupFiles
     }
   }
 
-  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 
@@ -448,7 +455,8 @@ public class BackupFiles
       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)
@@ -467,8 +475,7 @@ public class BackupFiles
   }
 
   public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
-          String fileName,
-          String suffix, int digits)
+          String fileName, String suffix, int digits)
   {
     File[] backupFiles = null;
 
@@ -489,11 +496,12 @@ public class BackupFiles
 
     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<>();
@@ -510,6 +518,4 @@ public class BackupFiles
     return bfTreeMap;
   }
 
-
 }
-