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 |
|
|
|
|
| 62.2% |
Uncovered Elements: 28 (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 |
1 |
public BackupFilenameParts(File file, String base, String template,... |
45 |
|
int digits) |
46 |
|
{ |
47 |
1 |
this(file.getName(), base, template, digits); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
516 |
public BackupFilenameParts(String filename, String base, String template,... |
51 |
|
int suggesteddigits) |
52 |
|
{ |
53 |
516 |
this(filename, base, template, suggesteddigits, false); |
54 |
|
} |
55 |
|
|
|
|
| 71.1% |
Uncovered Elements: 13 (45) |
Complexity: 15 |
Complexity Density: 0.52 |
|
56 |
516 |
public BackupFilenameParts(String filename, String base, String template,... |
57 |
|
int suggesteddigits, boolean extensionMatch) |
58 |
|
{ |
59 |
516 |
this.isBackupFile = false; |
60 |
|
|
61 |
516 |
int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER); |
62 |
516 |
int digits = 0; |
63 |
516 |
String templateStart = template; |
64 |
516 |
String templateEnd = ""; |
65 |
516 |
if (numcharstart > -1) |
66 |
|
{ |
67 |
516 |
templateStart = template.substring(0, numcharstart); |
68 |
516 |
templateEnd = template.substring( |
69 |
|
numcharstart + BackupFiles.NUM_PLACEHOLDER.length()); |
70 |
516 |
digits = suggesteddigits; |
71 |
|
} |
72 |
|
|
73 |
516 |
String savedFilename = ""; |
74 |
|
|
75 |
|
|
76 |
516 |
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 |
516 |
int minlength = base.length() + template.length() |
96 |
|
- BackupFiles.NUM_PLACEHOLDER.length() + digits; |
97 |
|
|
98 |
516 |
if (!(filename.startsWith(base + templateStart) |
99 |
|
&& filename.endsWith(templateEnd) |
100 |
|
&& filename.length() >= minlength)) |
101 |
|
{ |
102 |
|
|
103 |
514 |
return; |
104 |
|
} |
105 |
|
|
106 |
2 |
int startLength = base.length() + templateStart.length(); |
107 |
2 |
int endLength = templateEnd.length(); |
108 |
2 |
String numString = numcharstart > -1 |
109 |
|
? filename.substring(startLength, filename.length() - endLength) |
110 |
|
: ""; |
111 |
|
|
112 |
2 |
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 |
2 |
this.base = extensionMatch ? savedFilename + base : base; |
122 |
2 |
this.templateStart = templateStart; |
123 |
2 |
this.num = numString.length() > 0 ? Integer.parseInt(numString) : 0; |
124 |
2 |
this.digits = digits; |
125 |
2 |
this.templateEnd = templateEnd; |
126 |
2 |
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 |
515 |
public boolean isBackupFile()... |
155 |
|
{ |
156 |
515 |
return this.isBackupFile; |
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
1 |
public int indexNum()... |
160 |
|
{ |
161 |
1 |
return this.num; |
162 |
|
} |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
164 |
2 |
public static String getBackupFilename(int index, String base,... |
165 |
|
String template, int digits) |
166 |
|
{ |
167 |
2 |
String numString = String.format("%0" + digits + "d", index); |
168 |
2 |
String backupSuffix = template.replaceFirst(BackupFiles.NUM_PLACEHOLDER, |
169 |
|
numString); |
170 |
2 |
String backupfilename = base + backupSuffix; |
171 |
2 |
return backupfilename; |
172 |
|
} |
173 |
|
} |