Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.io

File BackupFilesPresetEntry.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

14
48
6
1
193
136
14
0.29
8
6
2.33

Classes

Class Line # Actions
BackupFilesPresetEntry 30 48 14
0.911764791.2%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import jalview.bin.Cache;
24    import jalview.util.MessageManager;
25   
26    import java.util.HashMap;
27    import java.util.Map;
28    import java.util.StringTokenizer;
29   
 
30    public class BackupFilesPresetEntry
31    {
32   
33    public String suffix;
34   
35    public static final int DIGITSMIN = 1;
36   
37    public static final int DIGITSMAX = 6;
38   
39    public int digits;
40   
41    public boolean reverse;
42   
43    public boolean keepAll;
44   
45    public static final int ROLLMAXMIN = 1;
46   
47    public static final int ROLLMAXMAX = 999;
48   
49    public int rollMax;
50   
51    public boolean confirmDelete;
52   
53    public static final String SAVEDCONFIG = BackupFiles.NS + "_SAVED";
54   
55    public static final String CUSTOMCONFIG = BackupFiles.NS + "_CUSTOM";
56   
57    private static final String stringDelim = "\t";
58   
59    public static final int BACKUPFILESSCHEMECUSTOM = 0;
60   
61    public static final int BACKUPFILESSCHEMEDEFAULT = 1;
62   
 
63  165 toggle public BackupFilesPresetEntry(String suffix, int digits, boolean reverse,
64    boolean keepAll, int rollMax, boolean confirmDelete)
65    {
66  165 this.suffix = suffix == null ? "" : suffix;
67  165 this.digits = digits < DIGITSMIN ? DIGITSMIN
68  156 : (digits > DIGITSMAX ? DIGITSMAX : digits);
69  165 this.reverse = reverse;
70  165 this.keepAll = keepAll;
71  165 this.rollMax = rollMax < ROLLMAXMIN ? ROLLMAXMIN
72  156 : (rollMax > ROLLMAXMAX ? ROLLMAXMAX : rollMax);
73  165 this.confirmDelete = confirmDelete;
74    }
75   
 
76  0 toggle public boolean equals(BackupFilesPresetEntry compare)
77    {
78  0 return suffix.equals(compare.suffix) && digits == compare.digits
79    && reverse == compare.reverse && keepAll == compare.keepAll
80    && rollMax == compare.rollMax
81    && confirmDelete == compare.confirmDelete;
82    }
83   
 
84  4 toggle @Override
85    public String toString()
86    {
87  4 StringBuilder sb = new StringBuilder();
88  4 sb.append(suffix);
89  4 sb.append(stringDelim);
90  4 sb.append(digits);
91  4 sb.append(stringDelim);
92  4 sb.append(reverse);
93  4 sb.append(stringDelim);
94  4 sb.append(keepAll);
95  4 sb.append(stringDelim);
96  4 sb.append(rollMax);
97  4 sb.append(stringDelim);
98  4 sb.append(confirmDelete);
99  4 return sb.toString();
100    }
101   
 
102  140 toggle public static BackupFilesPresetEntry createBackupFilesPresetEntry(
103    String line)
104    {
105  140 if (line == null)
106    {
107  24 return null;
108    }
109  116 StringTokenizer st = new StringTokenizer(line, stringDelim);
110  116 String suffix = null;
111  116 int digits = 0;
112  116 boolean reverse = false;
113  116 boolean keepAll = false;
114  116 int rollMax = 0;
115  116 boolean confirmDelete = false;
116   
117  116 try
118    {
119  116 suffix = st.nextToken();
120  116 digits = Integer.valueOf(st.nextToken());
121  116 reverse = Boolean.valueOf(st.nextToken());
122  116 keepAll = Boolean.valueOf(st.nextToken());
123  116 rollMax = Integer.valueOf(st.nextToken());
124  116 confirmDelete = Boolean.valueOf(st.nextToken());
125    } catch (Exception e)
126    {
127  0 Cache.log.error("Error parsing backupfiles scheme '" + line + "'");
128    }
129   
130  116 return new BackupFilesPresetEntry(suffix, digits, reverse, keepAll,
131    rollMax, confirmDelete);
132    }
133   
 
134  140 toggle public static BackupFilesPresetEntry getSavedBackupEntry()
135    {
136  140 String savedPresetString = Cache
137    .getDefault(BackupFilesPresetEntry.SAVEDCONFIG, null);
138  140 BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
139    .createBackupFilesPresetEntry(savedPresetString);
140  140 if (savedPreset == null)
141    {
142  24 savedPreset = backupfilesPresetEntriesValues
143    .get(BACKUPFILESSCHEMEDEFAULT);
144    }
145  140 return savedPreset;
146    }
147   
148    public static final IntKeyStringValueEntry[] backupfilesPresetEntries = {
149    new IntKeyStringValueEntry(BACKUPFILESSCHEMEDEFAULT,
150    MessageManager.getString("label.default")),
151    new IntKeyStringValueEntry(2,
152    MessageManager.getString("label.single_file")),
153    new IntKeyStringValueEntry(3,
154    MessageManager.getString("label.keep_all_versions")),
155    new IntKeyStringValueEntry(4,
156    MessageManager.getString("label.rolled_backups")),
157    // ...
158    // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
159    new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOM,
160    MessageManager.getString("label.custom")) };
161   
162    public static final String[] backupfilesPresetEntryDescriptions = {
163    MessageManager.getString("label.default_description"),
164    MessageManager.getString("label.single_file_description"),
165    MessageManager.getString("label.keep_all_versions_description"),
166    MessageManager.getString("label.rolled_backups_description"),
167    MessageManager.getString("label.custom_description") };
168   
169    public static final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
170    {
171    /**
172    *
173    */
174    private static final long serialVersionUID = 125L;
175   
 
176  9 toggle {
177  9 put(1, new BackupFilesPresetEntry(
178    ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
179    false));
180  9 put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
181  9 put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
182    3, false, true, 10, true));
183  9 put(4, new BackupFilesPresetEntry(
184    "_bak." + BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9,
185    false));
186   
187    // This gets replaced by GPreferences
188  9 put(BACKUPFILESSCHEMECUSTOM,
189    new BackupFilesPresetEntry("", 0, false, false, 0, false));
190    }
191    };
192   
193    }