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 |
|
import java.util.stream.Collectors; |
28 |
|
|
29 |
|
import jalview.bin.Console; |
30 |
|
import jalview.bin.argparser.Arg.Opt; |
31 |
|
import jalview.bin.argparser.Arg.Type; |
32 |
|
|
|
|
| 42.9% |
Uncovered Elements: 72 (126) |
Complexity: 49 |
Complexity Density: 0.69 |
|
33 |
|
public class ArgValues |
34 |
|
{ |
35 |
|
public static final String ID = "id"; |
36 |
|
|
37 |
|
private Arg arg; |
38 |
|
|
39 |
|
private int argCount = 0; |
40 |
|
|
41 |
|
private boolean boolValue = false; |
42 |
|
|
43 |
|
private boolean negated = false; |
44 |
|
|
45 |
|
private boolean setByWildcard = false; |
46 |
|
|
47 |
|
private String givenLinkedId = null; |
48 |
|
|
49 |
|
private int boolIndex = -1; |
50 |
|
|
51 |
|
private List<Integer> argsIndexes; |
52 |
|
|
53 |
|
private List<ArgValue> argValueList; |
54 |
|
|
55 |
|
private Map<String, ArgValue> idMap = new HashMap<>(); |
56 |
|
|
57 |
|
private ArgValuesMap avm; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private Type type = null; |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
64 |
1051 |
protected ArgValues(Arg a, ArgValuesMap avm)... |
65 |
|
{ |
66 |
1051 |
this.arg = a; |
67 |
1051 |
this.argValueList = new ArrayList<ArgValue>(); |
68 |
1051 |
this.boolValue = arg.getDefaultBoolValue(); |
69 |
1051 |
this.avm = avm; |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
protected boolean setByWildcard()... |
73 |
|
{ |
74 |
0 |
return setByWildcard; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
925 |
protected void setSetByWildcard(boolean b)... |
78 |
|
{ |
79 |
925 |
setByWildcard = b; |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
3728 |
public Arg arg()... |
83 |
|
{ |
84 |
3728 |
return arg; |
85 |
|
} |
86 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
87 |
319 |
protected void setType(Type t)... |
88 |
|
{ |
89 |
319 |
if (this.arg().hasOption(Opt.HASTYPE)) |
90 |
0 |
this.type = t; |
91 |
|
} |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
public Type getType()... |
94 |
|
{ |
95 |
0 |
return type; |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
protected int getCount()... |
99 |
|
{ |
100 |
0 |
return argCount; |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
925 |
protected void incrementCount()... |
104 |
|
{ |
105 |
925 |
argCount++; |
106 |
|
} |
107 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
108 |
134 |
protected void setNegated(boolean b, boolean beingSetByWildcard)... |
109 |
|
{ |
110 |
|
|
111 |
134 |
if (boolIndex >= 0 && !this.setByWildcard && beingSetByWildcard) |
112 |
0 |
return; |
113 |
134 |
this.negated = b; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0 |
protected boolean isNegated()... |
117 |
|
{ |
118 |
0 |
return this.negated; |
119 |
|
} |
120 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
121 |
319 |
protected void setBoolean(Type t, boolean b, int i,... |
122 |
|
boolean beingSetByWildcard, String givenLinkedId) |
123 |
|
{ |
124 |
319 |
this.setType(t); |
125 |
|
|
126 |
319 |
if (boolIndex >= 0 && !this.setByWildcard && beingSetByWildcard) |
127 |
0 |
return; |
128 |
319 |
this.boolValue = b; |
129 |
319 |
this.boolIndex = i; |
130 |
319 |
this.setSetByWildcard(beingSetByWildcard); |
131 |
319 |
this.givenLinkedId = givenLinkedId; |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
134 |
protected boolean getBoolean()... |
135 |
|
{ |
136 |
134 |
return this.boolValue; |
137 |
|
} |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
139 |
0 |
@Override... |
140 |
|
public String toString() |
141 |
|
{ |
142 |
0 |
if (argValueList == null) |
143 |
0 |
return null; |
144 |
0 |
StringBuilder sb = new StringBuilder(); |
145 |
0 |
sb.append(arg.toLongString()); |
146 |
0 |
if (arg.hasOption(Opt.BOOLEAN) || arg.hasOption(Opt.UNARY)) |
147 |
0 |
sb.append("Boolean: ").append(boolValue).append("; Default: ") |
148 |
|
.append(arg.getDefaultBoolValue()).append("; Negated: ") |
149 |
|
.append(negated).append("\n"); |
150 |
0 |
if (arg.hasOption(Opt.STRING)) |
151 |
|
{ |
152 |
0 |
sb.append("Values:"); |
153 |
0 |
sb.append("'") |
154 |
|
.append(String |
155 |
|
.join("',\n '", |
156 |
|
argValueList.stream().map(av -> av.getValue()) |
157 |
|
.collect(Collectors.toList()))) |
158 |
|
.append("'"); |
159 |
0 |
sb.append("\n"); |
160 |
|
} |
161 |
0 |
sb.append("Count: ").append(argCount).append("\n"); |
162 |
0 |
return sb.toString(); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
360 |
protected void addValue(Type type, String val, int argIndex,... |
166 |
|
boolean wildcard, String givenLinkedId) |
167 |
|
{ |
168 |
360 |
addArgValue(new ArgValue(arg(), type, val, argIndex, wildcard, |
169 |
|
givenLinkedId, avm.getLinkedId()), wildcard); |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
246 |
protected void addValue(SubVals sv, Type type, String content,... |
173 |
|
int argIndex, boolean wildcard, String givenLinkedId) |
174 |
|
{ |
175 |
246 |
addArgValue(new ArgValue(arg(), sv, type, content, argIndex, wildcard, |
176 |
|
givenLinkedId, avm.getLinkedId()), wildcard); |
177 |
|
} |
178 |
|
|
|
|
| 54.5% |
Uncovered Elements: 10 (22) |
Complexity: 9 |
Complexity Density: 0.64 |
|
179 |
606 |
protected void addArgValue(ArgValue av, boolean beingSetByWildcard)... |
180 |
|
{ |
181 |
|
|
182 |
606 |
boolean overwrite = !arg.hasOption(Opt.MULTIVALUE) && setByWildcard |
183 |
|
&& !beingSetByWildcard; |
184 |
606 |
if ((!arg.hasOption(Opt.MULTIVALUE) && argValueList.size() > 0) |
185 |
|
&& !overwrite) |
186 |
0 |
return; |
187 |
606 |
if (arg.hasOption(Opt.NODUPLICATEVALUES) |
188 |
|
&& this.containsValue(av.getValue())) |
189 |
0 |
return; |
190 |
|
|
191 |
606 |
if (argValueList == null || overwrite) |
192 |
|
{ |
193 |
0 |
argValueList = new ArrayList<ArgValue>(); |
194 |
|
} |
195 |
606 |
SubVals sv = new SubVals(av.getValue()); |
196 |
606 |
if (sv.has(ID)) |
197 |
|
{ |
198 |
0 |
String id = sv.get(ID); |
199 |
0 |
av.setId(id); |
200 |
0 |
idMap.put(id, av); |
201 |
|
} |
202 |
606 |
argValueList.add(av); |
203 |
606 |
this.setSetByWildcard(beingSetByWildcard); |
204 |
|
} |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
protected boolean hasValue(String val)... |
207 |
|
{ |
208 |
0 |
return argValueList.contains(val); |
209 |
|
} |
210 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
211 |
6 |
protected ArgValue getArgValue()... |
212 |
|
{ |
213 |
6 |
if (arg.hasOption(Opt.MULTIVALUE)) |
214 |
3 |
Console.warn("Requesting single value for multi value argument"); |
215 |
6 |
return argValueList.size() > 0 ? argValueList.get(0) : null; |
216 |
|
} |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
1935 |
protected List<ArgValue> getArgValueList()... |
219 |
|
{ |
220 |
1935 |
return argValueList; |
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
0 |
protected boolean hasId(String id)... |
224 |
|
{ |
225 |
0 |
return idMap.containsKey(id); |
226 |
|
} |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
228 |
0 |
protected ArgValue getId(String id)... |
229 |
|
{ |
230 |
0 |
return idMap.get(id); |
231 |
|
} |
232 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
233 |
0 |
private boolean containsValue(String v)... |
234 |
|
{ |
235 |
0 |
if (argValueList == null) |
236 |
0 |
return false; |
237 |
0 |
for (ArgValue av : argValueList) |
238 |
|
{ |
239 |
0 |
String val = av.getValue(); |
240 |
0 |
if (v == null && val == null) |
241 |
0 |
return true; |
242 |
0 |
if (v == null) |
243 |
0 |
continue; |
244 |
0 |
if (v.equals(val)) |
245 |
0 |
return true; |
246 |
|
} |
247 |
0 |
return false; |
248 |
|
} |
249 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
250 |
0 |
public boolean setByWildcardLinkedId()... |
251 |
|
{ |
252 |
|
|
253 |
0 |
return this.setByWildcard && this.givenLinkedId != null; |
254 |
|
} |
255 |
|
|
256 |
|
} |