1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.io; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.apache.commons.lang.ArrayUtils; |
22 |
|
import org.qedeq.base.utility.EqualsUtility; |
23 |
|
import org.qedeq.base.utility.StringUtility; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@author |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (99) |
Complexity: 34 |
Complexity Density: 0.62 |
|
37 |
|
public final class Path { |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
private final String[] path; |
42 |
|
|
43 |
|
|
44 |
|
private final String name; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
|
51 |
|
|
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
53 |
44
|
public Path(final String filePath) {... |
54 |
44
|
final String[] p = StringUtility.split(filePath, "/"); |
55 |
43
|
name = p[p.length - 1]; |
56 |
43
|
final String[] p2 = new String[p.length - 1]; |
57 |
43
|
System.arraycopy(p, 0, p2, 0, p2.length); |
58 |
43
|
path = removeRelativeDirs(p2); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
@param |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
69 |
16
|
public Path(final String dirPath, final String fileName) {... |
70 |
16
|
this((dirPath.endsWith("/") ? StringUtility.split(dirPath.substring(0, |
71 |
|
dirPath.length() - 1), "/") : StringUtility.split(dirPath, "/")), fileName); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
|
80 |
|
@param |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
82 |
30
|
public Path(final String[] dirNames, final String fileName) {... |
83 |
30
|
path = removeRelativeDirs(dirNames); |
84 |
29
|
name = (fileName != null ? fileName : ""); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
@return |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 9 |
Complexity Density: 0.56 |
|
94 |
15
|
public Path createRelative(final String filePath) {... |
95 |
15
|
final Path to = new Path(filePath); |
96 |
15
|
if (isRelative()) { |
97 |
|
|
98 |
4
|
return to; |
99 |
|
} |
100 |
11
|
if (to.isRelative()) { |
101 |
2
|
return to; |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
9
|
int max = 0; |
106 |
42
|
while (max < path.length && max < to.path.length) { |
107 |
38
|
if (!"..".equals(path[max]) && EqualsUtility.equals(path[max], to.path[max])) { |
108 |
33
|
max++; |
109 |
|
} else { |
110 |
5
|
break; |
111 |
|
} |
112 |
|
} |
113 |
9
|
final String[] r = new String[path.length - max + to.path.length - max]; |
114 |
17
|
for (int i = max; i < path.length; i++) { |
115 |
8
|
r[i - max] = ".."; |
116 |
|
} |
117 |
16
|
for (int i = max; i < to.path.length; i++) { |
118 |
7
|
r[i - max + path.length - max] = to.path[i]; |
119 |
|
} |
120 |
9
|
return new Path(r, to.name); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@return |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
17
|
public boolean isDirectory() {... |
129 |
17
|
return name.length() == 0; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@return |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
2
|
public boolean isFile() {... |
138 |
2
|
return !isDirectory(); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
56
|
public boolean isAbsolute() {... |
148 |
56
|
return path.length > 0 && (path[0].length() == 0 || path[0].endsWith(":")); |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
41
|
public boolean isRelative() {... |
157 |
41
|
return !isAbsolute(); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@return |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
15
|
public String getFileName() {... |
166 |
15
|
return name; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
@return |
174 |
|
|
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
176 |
15
|
public String getDirectory() {... |
177 |
15
|
StringBuffer result = new StringBuffer(256); |
178 |
54
|
for (int i = 0; i < path.length; i++) { |
179 |
39
|
result.append(path[i]).append("/"); |
180 |
|
} |
181 |
15
|
return result.toString(); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@param |
188 |
|
@return |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 8 |
Complexity Density: 0.67 |
|
190 |
73
|
private String[] removeRelativeDirs(final String[] dirNames) {... |
191 |
73
|
List d = new ArrayList(); |
192 |
314
|
for (int i = 0; i < dirNames.length; i++) { |
193 |
242
|
d.add(dirNames[i]); |
194 |
|
} |
195 |
314
|
for (int i = 0; i < d.size(); ) { |
196 |
242
|
if (i > 0 && "..".equals(d.get(i)) && !"".equals(d.get(i - 1)) |
197 |
|
&& !"..".equals(d.get(i - 1))) { |
198 |
9
|
d.remove(i - 1); |
199 |
9
|
d.remove(i - 1); |
200 |
9
|
i--; |
201 |
233
|
} else if (".".equals(d.get(i))) { |
202 |
3
|
d.remove(i); |
203 |
|
} else { |
204 |
230
|
i++; |
205 |
|
} |
206 |
|
} |
207 |
72
|
return (String[]) d.toArray(ArrayUtils.EMPTY_STRING_ARRAY); |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
210 |
40
|
public String toString() {... |
211 |
40
|
StringBuffer result = new StringBuffer(256); |
212 |
138
|
for (int i = 0; i < path.length; i++) { |
213 |
98
|
result.append(path[i]).append("/"); |
214 |
|
} |
215 |
40
|
result.append(name); |
216 |
40
|
return result.toString(); |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
219 |
12
|
public boolean equals(final Object obj) {... |
220 |
12
|
if (!(obj instanceof Path)) { |
221 |
3
|
return false; |
222 |
|
} |
223 |
9
|
final Path other = (Path) obj; |
224 |
9
|
return EqualsUtility.equals(path, other.path) && name.equals(other.name); |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
4
|
public int hashCode() {... |
228 |
4
|
return toString().hashCode(); |
229 |
|
} |
230 |
|
|
231 |
|
} |
232 |
|
|