1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.bin.argparser; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import jalview.bin.Console; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
|
|
| 71.1% |
Uncovered Elements: 28 (97) |
Complexity: 31 |
Complexity Density: 0.53 |
|
36 |
|
public class SubVals |
37 |
|
{ |
38 |
|
public static int NOTSET = -1; |
39 |
|
|
40 |
|
private int index = NOTSET; |
41 |
|
|
42 |
|
private Map<String, String> subValMap; |
43 |
|
|
44 |
|
private static char SEPARATOR = ','; |
45 |
|
|
46 |
|
private static char EQUALS = '='; |
47 |
|
|
48 |
|
private String content = null; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
314 |
protected SubVals(SubVals sv, String c)... |
51 |
|
{ |
52 |
314 |
this(sv, c, true); |
53 |
|
} |
54 |
|
|
|
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
55 |
314 |
protected SubVals(SubVals sv, String c, boolean merge)... |
56 |
|
{ |
57 |
314 |
SubVals subvals; |
58 |
314 |
if (merge) |
59 |
|
{ |
60 |
314 |
SubVals vsv = new SubVals(c); |
61 |
314 |
if (sv != null && sv.getSubValMap() != null) |
62 |
|
{ |
63 |
308 |
for (String key : sv.getSubValMap().keySet()) |
64 |
|
{ |
65 |
32 |
vsv.put(key, sv.get(key)); |
66 |
|
} |
67 |
|
} |
68 |
314 |
if (sv != null && sv.getIndex() > 0) |
69 |
|
{ |
70 |
10 |
vsv.index = sv.getIndex(); |
71 |
|
} |
72 |
314 |
subvals = vsv; |
73 |
|
} |
74 |
|
else |
75 |
|
{ |
76 |
|
|
77 |
0 |
subvals = sv; |
78 |
|
} |
79 |
314 |
if (subvals == null) |
80 |
|
{ |
81 |
0 |
this.subValMap = new HashMap<>(); |
82 |
|
} |
83 |
|
else |
84 |
|
{ |
85 |
314 |
this.subValMap = subvals == null ? new HashMap<>() |
86 |
|
: subvals.getSubValMap(); |
87 |
314 |
this.index = subvals.getIndex(); |
88 |
|
} |
89 |
314 |
this.content = c; |
90 |
|
} |
91 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
92 |
1198 |
protected SubVals(String item)... |
93 |
|
{ |
94 |
1198 |
if (subValMap == null) |
95 |
1198 |
subValMap = new HashMap<>(); |
96 |
1198 |
this.parseVals(item); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 7 |
Complexity Density: 0.35 |
|
99 |
1198 |
public void parseVals(String item)... |
100 |
|
{ |
101 |
1198 |
if (item == null) |
102 |
108 |
return; |
103 |
1090 |
if (item.indexOf('[') == 0 && item.indexOf(']') > 1) |
104 |
|
{ |
105 |
20 |
int openBracket = 0; |
106 |
20 |
int closeBracket = item.indexOf(']'); |
107 |
20 |
String subvalsString = item.substring(openBracket + 1, closeBracket); |
108 |
20 |
this.content = item.substring(closeBracket + 1); |
109 |
20 |
boolean setIndex = false; |
110 |
20 |
for (String subvalString : subvalsString |
111 |
|
.split(Character.toString(SEPARATOR))) |
112 |
|
{ |
113 |
44 |
int equals = subvalString.indexOf(EQUALS); |
114 |
44 |
if (equals > -1) |
115 |
|
{ |
116 |
18 |
this.put(subvalString.substring(0, equals), |
117 |
|
subvalString.substring(equals + 1)); |
118 |
|
} |
119 |
|
else |
120 |
|
{ |
121 |
26 |
try |
122 |
|
{ |
123 |
26 |
this.index = Integer.parseInt(subvalString); |
124 |
12 |
setIndex = true; |
125 |
|
} catch (NumberFormatException e) |
126 |
|
{ |
127 |
|
|
128 |
14 |
this.put(subvalString, "true"); |
129 |
|
} |
130 |
|
} |
131 |
|
} |
132 |
20 |
if (!setIndex) |
133 |
8 |
this.index = NOTSET; |
134 |
|
else |
135 |
12 |
Console.debug("SubVals from '" + subvalsString + "' has index " |
136 |
|
+ this.index + " set"); |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
1070 |
this.content = item; |
141 |
|
} |
142 |
|
} |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
64 |
protected void put(String key, String val)... |
145 |
|
{ |
146 |
64 |
subValMap.put(key, val); |
147 |
|
} |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0 |
public boolean notSet()... |
150 |
|
{ |
151 |
|
|
152 |
0 |
return index == NOTSET && (subValMap == null || subValMap.size() == 0); |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
0 |
public String getWithSubstitutions(ArgParser ap, String id, String key)... |
156 |
|
{ |
157 |
0 |
return ap.makeSubstitutions(subValMap.get(key), id); |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
345 |
public String get(String key)... |
161 |
|
{ |
162 |
345 |
return subValMap.get(key); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
1884 |
public boolean has(String key)... |
166 |
|
{ |
167 |
1884 |
return subValMap.containsKey(key); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
634 |
public int getIndex()... |
171 |
|
{ |
172 |
634 |
return index; |
173 |
|
} |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
316 |
public String getContent()... |
176 |
|
{ |
177 |
316 |
return content; |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
180 |
930 |
protected Map<String, String> getSubValMap()... |
181 |
|
{ |
182 |
930 |
return subValMap; |
183 |
|
} |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
185 |
0 |
public String toString()... |
186 |
|
{ |
187 |
0 |
if (subValMap == null && getIndex() == NOTSET) |
188 |
0 |
return ""; |
189 |
|
|
190 |
0 |
StringBuilder sb = new StringBuilder(); |
191 |
0 |
List<String> entries = new ArrayList<>(); |
192 |
0 |
subValMap.entrySet().stream().forEachOrdered( |
193 |
0 |
m -> entries.add(m.getValue().equals("true") ? m.getKey() |
194 |
|
: new StringBuilder().append(m.getKey()).append(EQUALS) |
195 |
|
.append(m.getValue()).toString())); |
196 |
0 |
if (getIndex() != NOTSET) |
197 |
0 |
entries.add(Integer.toString(getIndex())); |
198 |
0 |
sb.append('['); |
199 |
0 |
sb.append(String.join(Character.toString(SEPARATOR), entries)); |
200 |
0 |
sb.append(']'); |
201 |
0 |
return sb.toString(); |
202 |
|
} |
203 |
|
} |