1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.util; |
35 |
|
|
36 |
|
import org.apache.commons.lang3.StringUtils; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 16 |
Complexity Density: 0.67 |
|
51 |
|
public class PathSplitter { |
52 |
|
private static final String[] EMPTY = new String[0]; |
53 |
|
|
54 |
|
private final char separator; |
55 |
|
private final String[] pathElements; |
56 |
|
private int position; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
19 |
public PathSplitter(String source) {... |
62 |
19 |
this(source, true); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
24 |
public PathSplitter(String source, boolean trimExtension) {... |
69 |
24 |
this(source, '/', trimExtension); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 8 |
Complexity Density: 0.53 |
|
72 |
29 |
public PathSplitter(String source, char separator, boolean trimExtension) {... |
73 |
29 |
this.separator = separator; |
74 |
29 |
final String sep = String.valueOf(separator); |
75 |
29 |
if (source == null) { |
76 |
4 |
source = ""; |
77 |
|
} |
78 |
29 |
if (source.startsWith(sep)) { |
79 |
18 |
source = source.substring(1); |
80 |
|
} |
81 |
29 |
if (source.endsWith(sep)) { |
82 |
6 |
source = source.substring(0, source.length() - 1); |
83 |
|
} |
84 |
|
|
85 |
29 |
int dot = source.lastIndexOf('.'); |
86 |
29 |
if (dot < source.lastIndexOf(separator)) { |
87 |
11 |
dot = -1; |
88 |
|
} |
89 |
|
|
90 |
29 |
if (trimExtension && dot >= 0) { |
91 |
6 |
source = source.substring(0, dot); |
92 |
|
} |
93 |
|
|
94 |
29 |
this.pathElements = source.length() == 0 ? EMPTY : source.split(sep, -1); |
95 |
29 |
this.position = -1; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
18 |
public int count() {... |
102 |
18 |
return pathElements.length; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
108 |
22 |
public String next() {... |
109 |
22 |
position++; |
110 |
22 |
return position < pathElements.length ? pathElements[position] : ""; |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
116 |
23 |
public String skipTo(int index) {... |
117 |
23 |
position = index; |
118 |
23 |
return position < pathElements.length ? pathElements[position] : ""; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
128 |
14 |
public String remaining() {... |
129 |
14 |
position++; |
130 |
14 |
return StringUtils.join(pathElements, separator, position, pathElements.length); |
131 |
|
} |
132 |
|
} |