|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Path | Line # 37 | 55 | 34 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(58) | |||
Result | |||
0.53535354
|
org.qedeq.kernel.bo.service.unicode.GenerateUtf8Test.testGeneration3
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.unicode.GenerateUtf8Test.testGeneration4
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.unicode.GenerateUtf8Test.testGeneration2
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.unicode.Qedeq2UnicodeTextExecutorTest.testGeneration3
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.unicode.Qedeq2UnicodeTextExecutorTest.testGeneration4
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testGeneration
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.unicode.Qedeq2UnicodeTextExecutorTest.testGeneration2
![]() |
1 PASS | |
0.53535354
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testGeneration
![]() |
1 PASS | |
0.4949495
|
org.qedeq.kernel.bo.service.latex.Qedeq2LatexTest.testQ2L002
![]() |
1 PASS | |
0.4949495
|
org.qedeq.kernel.bo.service.latex.Qedeq2LatexTest.testQ2L003
![]() |
1 PASS | |
0.4949495
|
org.qedeq.kernel.bo.service.latex.Qedeq2LatexTest.testQ2L001_v1
![]() |
1 PASS | |
0.4949495
|
org.qedeq.kernel.bo.service.latex.Qedeq2LatexTest.testQ2L001_v2
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative02
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative02
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative08
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative07
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative07
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.heuristic.HeuristicCheckerPluginTest.testQedeqSetTheoryScript1
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative06
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative05
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative05
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative08
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.heuristic.HeuristicCheckerPluginTest.testQedeqSetTheoryScript2
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.logic.wf.FormulaCheckerContextTest.testPositive04
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.logic.wf.FormulaCheckerContextTest.testPositive03
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.heuristic.DynamicHeuristicCheckerPluginTest.testQedeqSampleScript1
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.logic.wf.FormulaCheckerContextTest.testPositive02
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.bo.service.latex.GenerateLatexTest.testNegative06
![]() |
1 PASS | |
0.46464646
|
org.qedeq.kernel.xml.dao.GenerateXmlTest.testGeneration
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_01
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_03
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_08
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_02
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_09
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_04
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_09c
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_04
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_05
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_10
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.module.VisitorContextTest.testContext
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_07
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_06
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_01
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_09
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.QedeqBoFactoryTest.testCreateStringQedeq5
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_07
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_09d
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_08
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_02
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_05
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_03
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.logic.QedeqBoFormalLogicCheckerTest.testCheckModule
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.QedeqBoFactoryTest.testCreateStringQedeq1
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_09b
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.QedeqBoFactoryTest.testCreateStringQedeq4
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_11
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.ModuleConstantsExistenceCheckerTest.testModuleConstantsExistenceChecker_12
![]() |
1 PASS | |
0.42424244
|
org.qedeq.kernel.bo.service.basis.LoadRequiredModulesTest.testLoadRequiredModules_06
![]() |
1 PASS | |
1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org | |
2 | * | |
3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. | |
4 | * | |
5 | * "Hilbert II" is free software; you can redistribute | |
6 | * it and/or modify it under the terms of the GNU General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
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 | * A file path that leads to a directory or file and is absolute or relative. | |
28 | * This abstraction of a file location was done to create relative file paths. | |
29 | * This class makes some assumptions about a file path: | |
30 | * "/" is the directory separator, "/" is also the root directory and ".." specifies | |
31 | * the parent directory. "." is the current directory. | |
32 | * A directory path must end with a "/" if a path ends not with a "/" it will be a file path | |
33 | * (but the empty path "" is a directory). | |
34 | * | |
35 | * @author Michael Meyling | |
36 | */ | |
37 | public final class Path { | |
38 | ||
39 | /** Directories that build up the path. If this is an absolute path the first | |
40 | * name is empty. */ | |
41 | private final String[] path; | |
42 | ||
43 | /** File name. */ | |
44 | private final String name; | |
45 | ||
46 | /** | |
47 | * Create file with given path and name. | |
48 | * | |
49 | * @param filePath Path to file with "/" as directory name separator. Relative directories | |
50 | * are removed from the file path if possible. Must not be | |
51 | * <code>null</code>. Might be "" this is called the <em>empty path</em>. | |
52 | */ | |
53 | 1374 |
![]() |
54 | 1374 | final String[] p = StringUtility.split(filePath, "/"); |
55 | 1373 | name = p[p.length - 1]; |
56 | 1373 | final String[] p2 = new String[p.length - 1]; |
57 | 1373 | System.arraycopy(p, 0, p2, 0, p2.length); |
58 | 1373 | path = removeRelativeDirs(p2); |
59 | } | |
60 | ||
61 | /** | |
62 | * Create file with given path and name. Relative directories are removed from | |
63 | * the file path if possible. | |
64 | * | |
65 | * @param dirPath Directory path to file with "/" as directory name separator. | |
66 | * This value can end with a "/" but it must not be <code>null</code>. | |
67 | * @param fileName File name. It should not contain "/" but this is not checked. | |
68 | */ | |
69 | 1987 |
![]() |
70 | 1987 | this((dirPath.endsWith("/") ? StringUtility.split(dirPath.substring(0, |
71 | dirPath.length() - 1), "/") : StringUtility.split(dirPath, "/")), fileName); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Create file with given path and name. Relative directories are removed | |
76 | * from the file path if possible. | |
77 | * | |
78 | * @param dirNames Directory names. If this is an absolute path the first | |
79 | * name is empty. Must not be <code>null</code>. | |
80 | * @param fileName File name. It should not contain "/" but this is not checked. | |
81 | */ | |
82 | 2012 |
![]() |
83 | 2012 | path = removeRelativeDirs(dirNames); |
84 | 2011 | name = (fileName != null ? fileName : ""); |
85 | } | |
86 | ||
87 | /** | |
88 | * Create new file path relative to given one. If the original path or <code>filePath</code> | |
89 | * is a relative path it will return <code>filePath</code>. | |
90 | * | |
91 | * @param filePath Path to file relative to <code>this</code>. | |
92 | * @return Relative file path (if possible). | |
93 | */ | |
94 | 31 |
![]() |
95 | 31 | final Path to = new Path(filePath); |
96 | 31 | if (isRelative()) { |
97 | // if from is relative, then we don't need to think further | |
98 | 9 | return to; |
99 | } | |
100 | 22 | if (to.isRelative()) { |
101 | 2 | return to; |
102 | } | |
103 | // both are absolute so we try to navigate within the file system | |
104 | // to get a relative path | |
105 | 20 | int max = 0; |
106 | 155 | while (max < path.length && max < to.path.length) { |
107 | 140 | if (!"..".equals(path[max]) && EqualsUtility.equals(path[max], to.path[max])) { |
108 | 135 | max++; |
109 | } else { | |
110 | 5 | break; |
111 | } | |
112 | } | |
113 | 20 | final String[] r = new String[path.length - max + to.path.length - max]; |
114 | 29 | for (int i = max; i < path.length; i++) { |
115 | 9 | r[i - max] = ".."; |
116 | } | |
117 | 33 | for (int i = max; i < to.path.length; i++) { |
118 | 13 | r[i - max + path.length - max] = to.path[i]; |
119 | } | |
120 | 20 | return new Path(r, to.name); |
121 | } | |
122 | ||
123 | /** | |
124 | * Describes this path a directory? | |
125 | * | |
126 | * @return Is directory? | |
127 | */ | |
128 | 17 |
![]() |
129 | 17 | return name.length() == 0; |
130 | } | |
131 | ||
132 | /** | |
133 | * Describes this path a file (and not a directory)? | |
134 | * | |
135 | * @return Is this a path to a file? | |
136 | */ | |
137 | 2 |
![]() |
138 | 2 | return !isDirectory(); |
139 | } | |
140 | ||
141 | /** | |
142 | * Is this an absolute path? If first path directory name is empty or ends with ":" | |
143 | * (MS windows tribute) this is the case. | |
144 | * | |
145 | * @return Is absolute path? | |
146 | */ | |
147 | 3345 |
![]() |
148 | 3345 | return path.length > 0 && (path[0].length() == 0 || path[0].endsWith(":")); |
149 | } | |
150 | ||
151 | /** | |
152 | * Is this a relative path? | |
153 | * | |
154 | * @return Is this a relative path? | |
155 | */ | |
156 | 1371 |
![]() |
157 | 1371 | return !isAbsolute(); |
158 | } | |
159 | ||
160 | /** | |
161 | * Get filename. Is "" if this is a pure directory path. | |
162 | * | |
163 | * @return File name. Might be "" but not <code>null</code>. | |
164 | */ | |
165 | 1318 |
![]() |
166 | 1318 | return name; |
167 | } | |
168 | ||
169 | /** | |
170 | * Get directory of this path. This might be a relative or absolute | |
171 | * path and ends with "/". (Only the empty path "" has no ending "/".) | |
172 | * | |
173 | * @return Directory this path points to. Will end with "/" if this is not | |
174 | * an empty path. | |
175 | */ | |
176 | 1318 |
![]() |
177 | 1318 | StringBuffer result = new StringBuffer(256); |
178 | 15301 | for (int i = 0; i < path.length; i++) { |
179 | 13983 | result.append(path[i]).append("/"); |
180 | } | |
181 | 1318 | return result.toString(); |
182 | } | |
183 | ||
184 | /** | |
185 | * Remove ".." and "." directories out of path if possible. | |
186 | * | |
187 | * @param dirNames Directories that build up the path. | |
188 | * @return Directories that build up the same path. | |
189 | */ | |
190 | 3385 |
![]() |
191 | 3385 | List d = new ArrayList(); |
192 | 20668 | for (int i = 0; i < dirNames.length; i++) { |
193 | 17284 | d.add(dirNames[i]); |
194 | } | |
195 | 20668 | for (int i = 0; i < d.size(); ) { |
196 | 17284 | if (i > 0 && "..".equals(d.get(i)) && !"".equals(d.get(i - 1)) |
197 | && !"..".equals(d.get(i - 1))) { | |
198 | 412 | d.remove(i - 1); |
199 | 412 | d.remove(i - 1); |
200 | 412 | i--; |
201 | 16872 | } else if (".".equals(d.get(i))) { |
202 | 3 | d.remove(i); |
203 | } else { | |
204 | 16869 | i++; |
205 | } | |
206 | } | |
207 | 3384 | return (String[]) d.toArray(ArrayUtils.EMPTY_STRING_ARRAY); |
208 | } | |
209 | ||
210 | 3969 |
![]() |
211 | 3969 | StringBuffer result = new StringBuffer(256); |
212 | 46014 | for (int i = 0; i < path.length; i++) { |
213 | 42045 | result.append(path[i]).append("/"); |
214 | } | |
215 | 3969 | result.append(name); |
216 | 3969 | return result.toString(); |
217 | } | |
218 | ||
219 | 12 |
![]() |
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 | ||
227 | 4 |
![]() |
228 | 4 | return toString().hashCode(); |
229 | } | |
230 | ||
231 | } | |
232 |
|