1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.service.logic; |
17 |
|
|
18 |
|
import java.util.HashMap; |
19 |
|
import java.util.Iterator; |
20 |
|
import java.util.Map; |
21 |
|
import java.util.Set; |
22 |
|
|
23 |
|
import org.qedeq.kernel.bo.common.ModuleReferenceList; |
24 |
|
import org.qedeq.kernel.bo.logic.common.ClassOperatorAlreadyExistsException; |
25 |
|
import org.qedeq.kernel.bo.logic.common.FunctionConstant; |
26 |
|
import org.qedeq.kernel.bo.logic.common.FunctionKey; |
27 |
|
import org.qedeq.kernel.bo.logic.common.IdentityOperatorAlreadyExistsException; |
28 |
|
import org.qedeq.kernel.bo.logic.common.PredicateConstant; |
29 |
|
import org.qedeq.kernel.bo.logic.common.PredicateKey; |
30 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
31 |
|
import org.qedeq.kernel.bo.module.ModuleConstantsExistenceChecker; |
32 |
|
import org.qedeq.kernel.se.base.module.Rule; |
33 |
|
import org.qedeq.kernel.se.common.IllegalModuleDataException; |
34 |
|
import org.qedeq.kernel.se.common.ModuleContext; |
35 |
|
import org.qedeq.kernel.se.common.ModuleDataException; |
36 |
|
import org.qedeq.kernel.se.common.RuleKey; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@author |
43 |
|
|
|
|
| 87.3% |
Uncovered Elements: 35 (275) |
Complexity: 70 |
Complexity Density: 0.4 |
|
44 |
|
public class ModuleConstantsExistenceCheckerImpl extends DefaultExistenceChecker |
45 |
|
implements ModuleConstantsExistenceChecker { |
46 |
|
|
47 |
|
|
48 |
|
private final KernelQedeqBo prop; |
49 |
|
|
50 |
|
|
51 |
|
private KernelQedeqBo classOperatorModule; |
52 |
|
|
53 |
|
|
54 |
|
private KernelQedeqBo identityOperatorModule; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
@throws |
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
63 |
305
|
public ModuleConstantsExistenceCheckerImpl(final KernelQedeqBo prop) throws ModuleDataException {... |
64 |
305
|
super(); |
65 |
305
|
this.prop = prop; |
66 |
305
|
init(); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@link |
74 |
|
|
75 |
|
@link |
76 |
|
|
77 |
|
@throws |
78 |
|
|
|
|
| 92.6% |
Uncovered Elements: 2 (27) |
Complexity: 7 |
Complexity Density: 0.41 |
|
79 |
305
|
public final void init() throws ModuleDataException {... |
80 |
305
|
clear(); |
81 |
305
|
final ModuleReferenceList list = prop.getRequiredModules(); |
82 |
305
|
final Map rules = new HashMap(); |
83 |
455
|
for (int i = 0; i < list.size(); i++) { |
84 |
152
|
final KernelQedeqBo bo = (KernelQedeqBo) list |
85 |
|
.getQedeqBo(i); |
86 |
152
|
if (bo.getExistenceChecker().identityOperatorExists()) { |
87 |
124
|
final String identityOperator = list.getLabel(i) + "." |
88 |
|
+ bo.getExistenceChecker().getIdentityOperator(); |
89 |
124
|
setIdentityOperatorDefined(identityOperator, |
90 |
|
bo.getExistenceChecker().getIdentityOperatorModule(), |
91 |
|
list.getModuleContext(i)); |
92 |
|
} |
93 |
150
|
if (bo.getExistenceChecker().classOperatorExists()) { |
94 |
13
|
setClassOperatorModule(bo.getExistenceChecker().getClassOperatorModule(), |
95 |
|
list.getModuleContext(i)); |
96 |
|
} |
97 |
150
|
final Map cut = bo.getExistenceChecker().getRules(); |
98 |
150
|
final Iterator iter = cut.keySet().iterator(); |
99 |
1528
|
while (iter.hasNext()) { |
100 |
1378
|
final RuleKey key = (RuleKey) iter.next(); |
101 |
1378
|
if (rules.containsKey(key) && !rules.get(key).equals(cut.get(key))) { |
102 |
0
|
throw new IllegalModuleDataException( |
103 |
|
LogicErrors.RULE_DEFINITIONS_DONT_MIX_CODE, |
104 |
|
LogicErrors.RULE_DEFINITIONS_DONT_MIX_TEXT + key + " in " |
105 |
|
+ ((KernelQedeqBo) rules.get(key)).getLabels().getRuleContext(key), |
106 |
|
list.getModuleContext(i), |
107 |
|
getQedeq(key).getLabels().getRuleContext(key)); |
108 |
|
} |
109 |
|
} |
110 |
150
|
rules.putAll(bo.getExistenceChecker().getRules()); |
111 |
|
} |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
114 |
51275
|
public boolean predicateExists(final PredicateKey predicate) {... |
115 |
51275
|
final String name = predicate.getName(); |
116 |
51275
|
final String arguments = predicate.getArguments(); |
117 |
51275
|
final int external = name.indexOf('.'); |
118 |
51275
|
if (external < 0) { |
119 |
37061
|
return super.predicateExists(predicate); |
120 |
|
} |
121 |
14214
|
final String label = name.substring(0, external); |
122 |
14214
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
123 |
|
|
124 |
14214
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref |
125 |
|
.getQedeqBo(label); |
126 |
14214
|
if (newProp == null) { |
127 |
2
|
return false; |
128 |
|
} |
129 |
14212
|
final String shortName = name.substring(external + 1); |
130 |
14212
|
return newProp.getExistenceChecker().predicateExists(new PredicateKey(shortName, arguments)); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
133 |
18679
|
public boolean functionExists(final FunctionKey function) {... |
134 |
18679
|
final String name = function.getName(); |
135 |
18679
|
final String arguments = function.getArguments(); |
136 |
18679
|
final int external = name.indexOf("."); |
137 |
18679
|
if (external < 0) { |
138 |
18673
|
return super.functionExists(function); |
139 |
|
} |
140 |
6
|
final String label = name.substring(0, external); |
141 |
6
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
142 |
6
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(label); |
143 |
6
|
if (newProp == null) { |
144 |
3
|
return false; |
145 |
|
} |
146 |
3
|
final String shortName = name.substring(external + 1); |
147 |
3
|
return newProp.getExistenceChecker().functionExists(new FunctionKey(shortName, arguments)); |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
150 |
5
|
public boolean isInitialPredicate(final PredicateKey predicate) {... |
151 |
5
|
final String name = predicate.getName(); |
152 |
5
|
final String arguments = predicate.getArguments(); |
153 |
5
|
final int external = name.indexOf('.'); |
154 |
5
|
if (external < 0) { |
155 |
2
|
return super.isInitialPredicate(predicate); |
156 |
|
} |
157 |
3
|
final String label = name.substring(0, external); |
158 |
3
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
159 |
|
|
160 |
3
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref |
161 |
|
.getQedeqBo(label); |
162 |
3
|
if (newProp == null) { |
163 |
1
|
return false; |
164 |
|
} |
165 |
2
|
final String shortName = name.substring(external + 1); |
166 |
2
|
return newProp.getExistenceChecker().isInitialPredicate( |
167 |
|
new PredicateKey(shortName, arguments)); |
168 |
|
} |
169 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
170 |
4
|
public boolean isInitialFunction(final FunctionKey function) {... |
171 |
4
|
final String name = function.getName(); |
172 |
4
|
final String arguments = function.getArguments(); |
173 |
4
|
final int external = name.indexOf('.'); |
174 |
4
|
if (external < 0) { |
175 |
2
|
return super.isInitialFunction(function); |
176 |
|
} |
177 |
2
|
final String label = name.substring(0, external); |
178 |
2
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
179 |
|
|
180 |
2
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref |
181 |
|
.getQedeqBo(label); |
182 |
2
|
if (newProp == null) { |
183 |
0
|
return false; |
184 |
|
} |
185 |
2
|
final String shortName = name.substring(external + 1); |
186 |
2
|
return newProp.getExistenceChecker().isInitialFunction( |
187 |
|
new FunctionKey(shortName, arguments)); |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
190 |
66996
|
public PredicateConstant get(final PredicateKey predicate) {... |
191 |
66996
|
final String name = predicate.getName(); |
192 |
66996
|
final String arguments = predicate.getArguments(); |
193 |
66996
|
final int external = name.indexOf('.'); |
194 |
66996
|
if (external < 0) { |
195 |
66991
|
return super.get(predicate); |
196 |
|
} |
197 |
5
|
final String label = name.substring(0, external); |
198 |
5
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
199 |
|
|
200 |
5
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref |
201 |
|
.getQedeqBo(label); |
202 |
5
|
if (newProp == null) { |
203 |
2
|
return null; |
204 |
|
} |
205 |
3
|
final String shortName = name.substring(external + 1); |
206 |
3
|
return newProp.getExistenceChecker().get(new PredicateKey(shortName, arguments)); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
209 |
6514
|
public FunctionConstant get(final FunctionKey function) {... |
210 |
6514
|
final String name = function.getName(); |
211 |
6514
|
final String arguments = function.getArguments(); |
212 |
6514
|
final int external = name.indexOf("."); |
213 |
6514
|
if (external < 0) { |
214 |
6508
|
return super.get(function); |
215 |
|
} |
216 |
6
|
final String label = name.substring(0, external); |
217 |
6
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
218 |
6
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref |
219 |
|
.getQedeqBo(label); |
220 |
6
|
if (newProp == null) { |
221 |
2
|
return null; |
222 |
|
} |
223 |
4
|
final String shortName = name.substring(external + 1); |
224 |
4
|
return newProp.getExistenceChecker().get(new FunctionKey(shortName, arguments)); |
225 |
|
} |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
@param |
231 |
|
@return |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
233 |
10
|
public KernelQedeqBo getQedeq(final FunctionKey function) {... |
234 |
10
|
final String name = function.getName(); |
235 |
10
|
final String arguments = function.getArguments(); |
236 |
10
|
final int external = name.indexOf("."); |
237 |
10
|
if (external < 0) { |
238 |
6
|
if (functionExists(function)) { |
239 |
2
|
return prop; |
240 |
|
} |
241 |
4
|
return null; |
242 |
|
} |
243 |
4
|
final String label = name.substring(0, external); |
244 |
4
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
245 |
4
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(label); |
246 |
4
|
if (newProp == null) { |
247 |
2
|
return newProp; |
248 |
|
} |
249 |
2
|
final String shortName = name.substring(external + 1); |
250 |
2
|
return newProp.getExistenceChecker().getQedeq(new FunctionKey(shortName, arguments)); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@param |
257 |
|
@return |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
259 |
10
|
public KernelQedeqBo getQedeq(final PredicateKey predicate) {... |
260 |
10
|
final String name = predicate.getName(); |
261 |
10
|
final String arguments = predicate.getArguments(); |
262 |
10
|
final int external = name.indexOf("."); |
263 |
10
|
if (external < 0) { |
264 |
6
|
if (predicateExists(predicate)) { |
265 |
2
|
return prop; |
266 |
|
} |
267 |
4
|
return null; |
268 |
|
} |
269 |
4
|
final String label = name.substring(0, external); |
270 |
4
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
271 |
4
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(label); |
272 |
4
|
if (newProp == null) { |
273 |
2
|
return newProp; |
274 |
|
} |
275 |
2
|
final String shortName = name.substring(external + 1); |
276 |
2
|
return newProp.getExistenceChecker().getQedeq(new PredicateKey(shortName, arguments)); |
277 |
|
} |
278 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 7 |
Complexity Density: 0.88 |
|
279 |
0
|
public RuleKey getRuleKey(final String ruleName) {... |
280 |
0
|
RuleKey ruleKey = prop.getLabels().getRuleKey(ruleName); |
281 |
0
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
282 |
0
|
for (int i = 0; i < ref.size(); i++) { |
283 |
0
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(i); |
284 |
0
|
final RuleKey found = newProp.getExistenceChecker().getRuleKey(ruleName); |
285 |
0
|
if (found != null && found.getVersion() != null && (ruleKey == null |
286 |
|
|| ruleKey.getVersion() == null |
287 |
|
|| 0 < found.getVersion().compareTo(ruleKey.getVersion()))) { |
288 |
0
|
ruleKey = found; |
289 |
|
} |
290 |
|
} |
291 |
0
|
return ruleKey; |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 7 |
Complexity Density: 0.88 |
|
294 |
0
|
public RuleKey getParentRuleKey(final String ruleName) {... |
295 |
0
|
RuleKey ruleKey = null; |
296 |
0
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
297 |
0
|
for (int i = 0; i < ref.size(); i++) { |
298 |
0
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(i); |
299 |
0
|
final RuleKey found = newProp.getExistenceChecker().getRuleKey(ruleName); |
300 |
0
|
if (found != null && found.getVersion() != null && (ruleKey == null |
301 |
|
|| ruleKey.getVersion() == null |
302 |
|
|| 0 < found.getVersion().compareTo(ruleKey.getVersion()))) { |
303 |
0
|
ruleKey = found; |
304 |
|
} |
305 |
|
} |
306 |
0
|
return ruleKey; |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
309 |
1722
|
public Rule get(final RuleKey ruleKey) {... |
310 |
1722
|
final Rule local = super.get(ruleKey); |
311 |
1722
|
if (null != local) { |
312 |
2
|
return local; |
313 |
|
} |
314 |
1720
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
315 |
1785
|
for (int i = 0; i < ref.size(); i++) { |
316 |
67
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(i); |
317 |
67
|
final Rule found = (newProp.getExistenceChecker().get(ruleKey)); |
318 |
67
|
if (found != null) { |
319 |
2
|
return found; |
320 |
|
} |
321 |
|
} |
322 |
1718
|
return null; |
323 |
|
} |
324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
325 |
544
|
public Map getRules() {... |
326 |
544
|
final Map result = new HashMap(); |
327 |
544
|
final Set keys = prop.getLabels().getRuleDefinitions().keySet(); |
328 |
544
|
final Iterator iter = keys.iterator(); |
329 |
4682
|
while (iter.hasNext()) { |
330 |
4138
|
result.put(iter.next(), prop); |
331 |
|
} |
332 |
544
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
333 |
619
|
for (int i = 0; i < ref.size(); i++) { |
334 |
75
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(i); |
335 |
75
|
result.putAll(newProp.getExistenceChecker().getRules()); |
336 |
|
} |
337 |
544
|
return result; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
@param |
344 |
|
@return |
345 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
346 |
3765
|
public KernelQedeqBo getQedeq(final RuleKey ruleKey) {... |
347 |
3765
|
if (super.get(ruleKey) != null) { |
348 |
3642
|
return prop; |
349 |
|
} |
350 |
123
|
final ModuleReferenceList ref = prop.getRequiredModules(); |
351 |
123
|
for (int i = 0; i < ref.size(); i++) { |
352 |
123
|
final KernelQedeqBo newProp = (KernelQedeqBo) ref.getQedeqBo(i); |
353 |
123
|
final KernelQedeqBo found = (newProp.getExistenceChecker().getQedeq(ruleKey)); |
354 |
123
|
if (found != null) { |
355 |
123
|
return found; |
356 |
|
} |
357 |
|
} |
358 |
0
|
return null; |
359 |
|
} |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
361 |
3148
|
public boolean classOperatorExists() {... |
362 |
3148
|
return classOperatorModule != null; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
@param |
369 |
|
@param |
370 |
|
@param |
371 |
|
@throws |
372 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
373 |
230
|
public void setIdentityOperatorDefined(final String identityOperator,... |
374 |
|
final KernelQedeqBo identityOperatorModule, final ModuleContext context) |
375 |
|
throws IdentityOperatorAlreadyExistsException { |
376 |
230
|
if (this.identityOperatorModule != null && identityOperatorModule != null) { |
377 |
19
|
if (!this.identityOperatorModule.equals(identityOperatorModule)) { |
378 |
8
|
throw new IdentityOperatorAlreadyExistsException( |
379 |
|
LogicErrors.IDENTITY_OPERATOR_ALREADY_EXISTS_CODE, |
380 |
|
LogicErrors.IDENTITY_OPERATOR_ALREADY_EXISTS_TEXT + " " + getIdentityOperator(), |
381 |
|
context); |
382 |
|
} |
383 |
|
} else { |
384 |
211
|
this.identityOperatorModule = identityOperatorModule; |
385 |
211
|
super.setIdentityOperatorDefined(identityOperator); |
386 |
|
} |
387 |
|
} |
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
6549
|
public KernelQedeqBo getClassOperatorModule() {... |
390 |
6549
|
return classOperatorModule; |
391 |
|
} |
392 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
393 |
124
|
public KernelQedeqBo getIdentityOperatorModule() {... |
394 |
124
|
return identityOperatorModule; |
395 |
|
} |
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
@param |
401 |
|
@param |
402 |
|
@throws |
403 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
404 |
88
|
public void setClassOperatorModule(final KernelQedeqBo classOperatorModule,... |
405 |
|
final ModuleContext context) throws ClassOperatorAlreadyExistsException { |
406 |
88
|
if (this.classOperatorModule != null && classOperatorModule != null) { |
407 |
|
|
408 |
|
|
409 |
1
|
if (!this.classOperatorModule.equals(classOperatorModule)) { |
410 |
0
|
throw new ClassOperatorAlreadyExistsException( |
411 |
|
LogicErrors.CLASS_OPERATOR_ALREADY_DEFINED_CODE, |
412 |
|
LogicErrors.CLASS_OPERATOR_ALREADY_DEFINED_TEXT |
413 |
|
+ this.classOperatorModule.getUrl(), |
414 |
|
context); |
415 |
|
} |
416 |
|
} else { |
417 |
87
|
this.classOperatorModule = classOperatorModule; |
418 |
|
} |
419 |
|
} |
420 |
|
|
421 |
|
} |