1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import java.io.File; |
24 |
|
|
|
|
| 66.2% |
Uncovered Elements: 25 (74) |
Complexity: 24 |
Complexity Density: 0.5 |
|
25 |
|
public class BackupFilenameParts |
26 |
|
{ |
27 |
|
private String base; |
28 |
|
|
29 |
|
private String templateStart; |
30 |
|
|
31 |
|
private int num; |
32 |
|
|
33 |
|
private int digits; |
34 |
|
|
35 |
|
private String templateEnd; |
36 |
|
|
37 |
|
private boolean isBackupFile; |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0 |
private BackupFilenameParts()... |
40 |
|
{ |
41 |
0 |
this.isBackupFile = false; |
42 |
|
} |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
150 |
public BackupFilenameParts(File file, String base, String template,... |
45 |
|
int digits) |
46 |
|
{ |
47 |
150 |
this(file.getName(), base, template, digits); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
6249 |
public BackupFilenameParts(String filename, String base, String template,... |
51 |
|
int suggesteddigits) |
52 |
|
{ |
53 |
6249 |
this(filename, base, template, suggesteddigits, false); |
54 |
|
} |
55 |
|
|
|
|
| 77.8% |
Uncovered Elements: 10 (45) |
Complexity: 15 |
Complexity Density: 0.52 |
|
56 |
6249 |
public BackupFilenameParts(String filename, String base, String template,... |
57 |
|
int suggesteddigits, boolean extensionMatch) |
58 |
|
{ |
59 |
6249 |
this.isBackupFile = false; |
60 |
|
|
61 |
6249 |
int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER); |
62 |
6249 |
int digits = 0; |
63 |
6249 |
String templateStart = template; |
64 |
6249 |
String templateEnd = ""; |
65 |
6249 |
if (numcharstart > -1) |
66 |
|
{ |
67 |
5985 |
templateStart = template.substring(0, numcharstart); |
68 |
5985 |
templateEnd = template.substring( |
69 |
|
numcharstart + BackupFiles.NUM_PLACEHOLDER.length()); |
70 |
5985 |
digits = suggesteddigits; |
71 |
|
} |
72 |
|
|
73 |
6249 |
String savedFilename = ""; |
74 |
|
|
75 |
|
|
76 |
6249 |
if (extensionMatch) |
77 |
|
{ |
78 |
|
|
79 |
|
|
80 |
0 |
int extensioncharstart = filename |
81 |
|
.lastIndexOf('.' + base + templateStart); |
82 |
0 |
if (extensioncharstart == -1) |
83 |
|
{ |
84 |
0 |
return; |
85 |
|
} |
86 |
|
|
87 |
0 |
savedFilename = filename.substring(0, extensioncharstart + 1); |
88 |
|
|
89 |
0 |
filename = filename.substring(extensioncharstart + 1); |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
6249 |
int minlength = base.length() + template.length() |
96 |
|
- BackupFiles.NUM_PLACEHOLDER.length() + digits; |
97 |
|
|
98 |
6249 |
if (!(filename.startsWith(base + templateStart) |
99 |
|
&& filename.endsWith(templateEnd) |
100 |
|
&& filename.length() >= minlength)) |
101 |
|
{ |
102 |
|
|
103 |
5949 |
return; |
104 |
|
} |
105 |
|
|
106 |
300 |
int startLength = base.length() + templateStart.length(); |
107 |
300 |
int endLength = templateEnd.length(); |
108 |
300 |
String numString = numcharstart > -1 |
109 |
|
? filename.substring(startLength, filename.length() - endLength) |
110 |
|
: ""; |
111 |
|
|
112 |
300 |
if (filename.length() >= startLength + digits + endLength |
113 |
|
&& filename.startsWith(base + templateStart) |
114 |
|
&& filename.endsWith(templateEnd) |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
&& (numString.matches("[0-9]{" + digits + "}") |
119 |
|
|| numString.matches("[1-9][0-9]{" + digits + ",}"))) |
120 |
|
{ |
121 |
300 |
this.base = extensionMatch ? savedFilename + base : base; |
122 |
300 |
this.templateStart = templateStart; |
123 |
300 |
this.num = numString.length() > 0 ? Integer.parseInt(numString) : 0; |
124 |
300 |
this.digits = digits; |
125 |
300 |
this.templateEnd = templateEnd; |
126 |
300 |
this.isBackupFile = true; |
127 |
|
} |
128 |
|
|
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
131 |
0 |
public static BackupFilenameParts currentBackupFilenameParts(... |
132 |
|
String filename, String base, boolean extensionMatch) |
133 |
|
{ |
134 |
0 |
BackupFilenameParts bfp = new BackupFilenameParts(); |
135 |
0 |
BackupFilesPresetEntry bfpe = BackupFilesPresetEntry |
136 |
|
.getSavedBackupEntry(); |
137 |
0 |
String template = bfpe.suffix; |
138 |
0 |
if (template == null) |
139 |
|
{ |
140 |
0 |
return bfp; |
141 |
|
} |
142 |
0 |
int digits; |
143 |
0 |
try |
144 |
|
{ |
145 |
0 |
digits = bfpe.digits; |
146 |
|
} catch (Exception e) |
147 |
|
{ |
148 |
0 |
return bfp; |
149 |
|
} |
150 |
0 |
return new BackupFilenameParts(filename, base, template, digits, |
151 |
|
extensionMatch); |
152 |
|
} |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
6099 |
public boolean isBackupFile()... |
155 |
|
{ |
156 |
6099 |
return this.isBackupFile; |
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
150 |
public int indexNum()... |
160 |
|
{ |
161 |
150 |
return this.num; |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
164 |
78 |
public static String getBackupFilename(int index, String base,... |
165 |
|
String template, int digits) |
166 |
|
{ |
167 |
78 |
String numString = String.format("%0" + digits + "d", index); |
168 |
78 |
String backupSuffix = template.replaceFirst(BackupFiles.NUM_PLACEHOLDER, |
169 |
|
numString); |
170 |
78 |
String backupfilename = base + backupSuffix; |
171 |
78 |
return backupfilename; |
172 |
|
} |
173 |
|
} |