1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.qedeq.kernel.xml.tracker; |
19 |
|
|
20 |
|
import java.util.ArrayList; |
21 |
|
import java.util.List; |
22 |
|
import java.util.StringTokenizer; |
23 |
|
|
24 |
|
import org.qedeq.base.utility.EqualsUtility; |
25 |
|
import org.qedeq.kernel.common.SourcePosition; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
@author |
33 |
|
|
|
|
| 68% |
Uncovered Elements: 80 (250) |
Complexity: 68 |
Complexity Density: 0,48 |
|
34 |
|
public class SimpleXPath { |
35 |
|
|
36 |
|
|
37 |
|
private final List elements; |
38 |
|
|
39 |
|
|
40 |
|
private final List numbers; |
41 |
|
|
42 |
|
|
43 |
|
private String attribute; |
44 |
|
|
45 |
|
|
46 |
|
private SourcePosition start; |
47 |
|
|
48 |
|
|
49 |
|
private SourcePosition end; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
|
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
70 |
32624
|
public SimpleXPath(final String xpath) {... |
71 |
32624
|
elements = new ArrayList(); |
72 |
32624
|
numbers = new ArrayList(); |
73 |
32624
|
attribute = null; |
74 |
32624
|
init(xpath); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
80 |
97658
|
public SimpleXPath() {... |
81 |
97658
|
elements = new ArrayList(); |
82 |
97658
|
numbers = new ArrayList(); |
83 |
97658
|
attribute = null; |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@param |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
91 |
338744
|
public SimpleXPath(final SimpleXPath original) {... |
92 |
338744
|
elements = new ArrayList(); |
93 |
338744
|
numbers = new ArrayList(); |
94 |
338744
|
attribute = null; |
95 |
338744
|
init(original.toString()); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@see |
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
|
|
|
| 94% |
Uncovered Elements: 3 (50) |
Complexity: 13 |
Complexity Density: 0,43 |
|
106 |
371368
|
private void init(final String xpath) {... |
107 |
371368
|
if (xpath == null) { |
108 |
0
|
throw new NullPointerException(); |
109 |
|
} |
110 |
371368
|
if (xpath.length() <= 0) { |
111 |
1
|
throw new RuntimeException("XPath must not be empty"); |
112 |
|
} |
113 |
371367
|
if (xpath.charAt(0) != '/') { |
114 |
2
|
throw new RuntimeException("XPath must start with '/': " + xpath); |
115 |
|
} |
116 |
371365
|
if (xpath.indexOf("//") >= 0) { |
117 |
1
|
throw new RuntimeException("empty tag not permitted: " + xpath); |
118 |
|
} |
119 |
371364
|
if (xpath.endsWith("/")) { |
120 |
1
|
throw new RuntimeException("XPath must not end with '/': " + xpath); |
121 |
|
} |
122 |
371363
|
final StringTokenizer tokenizer = new StringTokenizer(xpath, "/"); |
123 |
2160066
|
while (tokenizer.hasMoreTokens()) { |
124 |
1788705
|
String token = tokenizer.nextToken(); |
125 |
1788705
|
if (!tokenizer.hasMoreTokens() && token.indexOf('@') >= 0) { |
126 |
3689
|
attribute = token.substring(token.indexOf('@') + 1); |
127 |
3689
|
if (attribute.length() <= 0) { |
128 |
1
|
throw new RuntimeException("empty attribute not permitted: " + xpath); |
129 |
|
} |
130 |
3688
|
token = token.substring(0, token.indexOf('@')); |
131 |
|
} |
132 |
1788704
|
if (token.indexOf('[') < 0) { |
133 |
1167433
|
elements.add(token); |
134 |
1167433
|
numbers.add(new Integer(1)); |
135 |
|
} else { |
136 |
621271
|
final StringTokenizer getnu = new StringTokenizer(token, "[]"); |
137 |
621271
|
elements.add(getnu.nextToken()); |
138 |
621271
|
final Integer i; |
139 |
621271
|
try { |
140 |
621271
|
i = new Integer(getnu.nextToken()); |
141 |
|
} catch (RuntimeException e) { |
142 |
0
|
throw new RuntimeException("not an integer: " + xpath, e); |
143 |
|
} |
144 |
621271
|
if (i.intValue() <= 0) { |
145 |
1
|
throw new RuntimeException("integer must be greater zero: " + xpath); |
146 |
|
} |
147 |
621270
|
numbers.add(i); |
148 |
|
} |
149 |
|
} |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@return |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
294987284
|
public final int size() {... |
158 |
294987284
|
return elements.size(); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@param@link |
165 |
|
@return |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
167 |
137703290
|
public final String getElementName(final int i) {... |
168 |
137703290
|
return (String) elements.get(i); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param@link |
175 |
|
@return |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
92137561
|
public final int getElementOccurrence(final int i) {... |
178 |
92137561
|
return ((Integer) numbers.get(i)).intValue(); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
186 |
0
|
public final void addElement(final String elementName) {... |
187 |
0
|
attribute = null; |
188 |
0
|
elements.add(elementName); |
189 |
0
|
numbers.add(new Integer(1)); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
@param |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
198 |
139543877
|
public final void addElement(final String elementName, final int occurrence) {... |
199 |
139543877
|
attribute = null; |
200 |
139543877
|
elements.add(elementName); |
201 |
139543877
|
numbers.add(new Integer(occurrence)); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
209 |
0
|
public final String getLastElement() {... |
210 |
0
|
int size = elements.size(); |
211 |
0
|
if (size <= 0) { |
212 |
0
|
return null; |
213 |
|
} |
214 |
0
|
return (String) elements.get(size - 1); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
@return |
221 |
|
|
222 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
223 |
0
|
public final String getBeforeLastElement() {... |
224 |
0
|
int size = elements.size(); |
225 |
0
|
if (size <= 1) { |
226 |
0
|
return null; |
227 |
|
} |
228 |
0
|
return (String) elements.get(size - 2); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
|
|
| 85,7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
234 |
139248532
|
public void deleteLastElement() {... |
235 |
139248532
|
int size = elements.size(); |
236 |
139248532
|
if (size > 0) { |
237 |
139248532
|
elements.remove(size - 1); |
238 |
139248532
|
numbers.remove(size - 1); |
239 |
139248532
|
attribute = null; |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
@param |
247 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
248 |
768215
|
public final void setAttribute(final String attribute) {... |
249 |
768215
|
this.attribute = attribute; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
@return |
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
257 |
443934
|
public final String getAttribute() {... |
258 |
443934
|
return attribute; |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
@param |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
35974
|
public final void setStartLocation(final SourcePosition position) {... |
267 |
35974
|
start = position; |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
@return |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
32705
|
public final SourcePosition getStartLocation() {... |
276 |
32705
|
return start; |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@param |
283 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
32555
|
public final void setEndLocation(final SourcePosition position) {... |
285 |
32555
|
end = position; |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
@return |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
293 |
32569
|
public final SourcePosition getEndLocation() {... |
294 |
32569
|
return end; |
295 |
|
} |
296 |
|
|
|
|
| 92,3% |
Uncovered Elements: 2 (26) |
Complexity: 7 |
Complexity Density: 0,5 |
|
297 |
53
|
public final boolean equals(final Object obj) {... |
298 |
53
|
if (!(obj instanceof SimpleXPath)) { |
299 |
0
|
return false; |
300 |
|
} |
301 |
53
|
final SimpleXPath other = (SimpleXPath) obj; |
302 |
53
|
if (!EqualsUtility.equals(this.getAttribute(), other.getAttribute())) { |
303 |
19
|
return false; |
304 |
|
} |
305 |
34
|
final int size = this.size(); |
306 |
34
|
if (size != other.size()) { |
307 |
15
|
return false; |
308 |
|
} |
309 |
|
|
310 |
62
|
for (int i = 0; i < size; i++) { |
311 |
51
|
if (!EqualsUtility.equals(this.getElementName(i), other.getElementName(i))) { |
312 |
7
|
return false; |
313 |
|
} |
314 |
44
|
if (this.getElementOccurrence(i) != other.getElementOccurrence(i)) { |
315 |
1
|
return false; |
316 |
|
} |
317 |
|
} |
318 |
11
|
return true; |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
@param |
326 |
|
@return |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0,56 |
|
328 |
0
|
public final boolean equalsElements(final SimpleXPath other) {... |
329 |
0
|
final int size = this.size(); |
330 |
0
|
if (size != other.size()) { |
331 |
0
|
return false; |
332 |
|
} |
333 |
|
|
334 |
0
|
for (int i = 0; i < size; i++) { |
335 |
0
|
if (!EqualsUtility.equals(this.getElementName(i), other.getElementName(i))) { |
336 |
0
|
return false; |
337 |
|
} |
338 |
0
|
if (getElementOccurrence(i) != other.getElementOccurrence(i)) { |
339 |
0
|
return false; |
340 |
|
} |
341 |
|
} |
342 |
0
|
return true; |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
@param |
350 |
|
|
351 |
|
@param |
352 |
|
|
353 |
|
@return |
354 |
|
|
|
|
| 72,4% |
Uncovered Elements: 8 (29) |
Complexity: 8 |
Complexity Density: 0,53 |
|
355 |
138657314
|
public final boolean matchesElements(final SimpleXPath current,... |
356 |
|
final SimpleXPath currentSummary) { |
357 |
138657314
|
final int size = current.size(); |
358 |
138657314
|
if (size != size()) { |
359 |
123144712
|
return false; |
360 |
|
} |
361 |
15512602
|
if (size != currentSummary.size()) { |
362 |
0
|
throw new IllegalArgumentException("summary size doesn't match"); |
363 |
|
} |
364 |
|
|
365 |
45369954
|
for (int i = 0; i < size; i++) { |
366 |
45304844
|
if ("*".equals(getElementName(i))) { |
367 |
0
|
if (getElementOccurrence(i) != currentSummary.getElementOccurrence(i)) { |
368 |
0
|
return false; |
369 |
|
} |
370 |
0
|
continue; |
371 |
|
} |
372 |
45304844
|
if (!EqualsUtility.equals(current.getElementName(i), getElementName(i))) { |
373 |
441060
|
return false; |
374 |
|
} |
375 |
44863784
|
if (current.getElementOccurrence(i) != getElementOccurrence(i)) { |
376 |
15006432
|
return false; |
377 |
|
} |
378 |
|
} |
379 |
65110
|
return true; |
380 |
|
} |
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
@param |
387 |
|
|
388 |
|
@param |
389 |
|
|
390 |
|
@return |
391 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0,53 |
|
392 |
0
|
public final boolean matchesElementsBegining(final SimpleXPath current,... |
393 |
|
final SimpleXPath currentSummary) { |
394 |
0
|
final int size = current.size(); |
395 |
0
|
if (size > size()) { |
396 |
0
|
return false; |
397 |
|
} |
398 |
0
|
if (size != currentSummary.size()) { |
399 |
0
|
throw new IllegalArgumentException("summary size doesn't match"); |
400 |
|
} |
401 |
|
|
402 |
0
|
for (int i = 0; i < size; i++) { |
403 |
0
|
if ("*".equals(getElementName(i))) { |
404 |
0
|
if (getElementOccurrence(i) != currentSummary.getElementOccurrence(i)) { |
405 |
0
|
return false; |
406 |
|
} |
407 |
0
|
continue; |
408 |
|
} |
409 |
0
|
if (!EqualsUtility.equals(current.getElementName(i), getElementName(i))) { |
410 |
0
|
return false; |
411 |
|
} |
412 |
0
|
if (current.getElementOccurrence(i) != getElementOccurrence(i)) { |
413 |
0
|
return false; |
414 |
|
} |
415 |
|
} |
416 |
0
|
return true; |
417 |
|
} |
418 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 4 |
Complexity Density: 0,33 |
|
419 |
371299
|
public final String toString() {... |
420 |
371299
|
final StringBuffer buffer = new StringBuffer(); |
421 |
2159771
|
for (int i = 0; i < size(); i++) { |
422 |
1788472
|
buffer.append("/"); |
423 |
1788472
|
buffer.append(getElementName(i)); |
424 |
1788472
|
if (getElementOccurrence(i) != 1) { |
425 |
621249
|
buffer.append("["); |
426 |
621249
|
buffer.append(getElementOccurrence(i)); |
427 |
621249
|
buffer.append("]"); |
428 |
|
} |
429 |
|
} |
430 |
371299
|
if (getAttribute() != null) { |
431 |
3667
|
buffer.append("@"); |
432 |
3667
|
buffer.append(getAttribute()); |
433 |
|
} |
434 |
371299
|
return buffer.toString(); |
435 |
|
} |
436 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0,38 |
|
437 |
46
|
public final int hashCode() {... |
438 |
46
|
int code = 0; |
439 |
46
|
if (attribute != null) { |
440 |
14
|
code ^= attribute.hashCode(); |
441 |
|
} |
442 |
210
|
for (int i = 0; i < size(); i++) { |
443 |
164
|
code ^= i + 1; |
444 |
164
|
code ^= getElementName(i).hashCode(); |
445 |
164
|
code ^= getElementOccurrence(i); |
446 |
|
} |
447 |
46
|
return code; |
448 |
|
} |
449 |
|
|
450 |
|
} |