Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart9.png 34% of files have more coverage
33   206   18   2.06
4   90   0.55   16
16     1.12  
1    
 
  DefaultExistenceChecker       Line # 35 33 18 88.7% 0.8867925
 
  (35)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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.kernel.bo.module;
17   
18    import java.util.HashMap;
19    import java.util.Map;
20   
21    import org.qedeq.base.trace.Trace;
22    import org.qedeq.kernel.base.module.FunctionDefinition;
23    import org.qedeq.kernel.base.module.PredicateDefinition;
24    import org.qedeq.kernel.bo.logic.wf.ExistenceChecker;
25    import org.qedeq.kernel.bo.logic.wf.Function;
26    import org.qedeq.kernel.bo.logic.wf.HigherLogicalErrors;
27    import org.qedeq.kernel.bo.logic.wf.Predicate;
28   
29   
30    /**
31    * Checks if all predicate and function constants exist already.
32    *
33    * @author Michael Meyling
34    */
 
35    public class DefaultExistenceChecker implements ExistenceChecker {
36   
37    /** This class. */
38    private static final Class CLASS = DefaultExistenceChecker.class;
39   
40    /** Maps {@link Predicate} identifiers to {@link PredicateDefinition}s. */
41    private final Map predicateDefinitions = new HashMap();
42   
43    /** Maps {@link Function} identifiers to {@link FunctionDefinition}s. */
44    private final Map functionDefinitions = new HashMap();
45   
46    /** Is the class operator already defined? */
47    private boolean setDefinitionByFormula;
48   
49    /** Identity operator. */
50    private String identityOperator;
51   
52   
53    /**
54    * Constructor.
55    */
 
56  97 toggle public DefaultExistenceChecker() {
57  97 clear();
58    }
59   
60    /**
61    * Empty all definitions.
62    */
 
63  194 toggle public void clear() {
64  194 Trace.trace(CLASS, this, "setClassOperatorExists", "clear");
65  194 predicateDefinitions.clear();
66  194 functionDefinitions.clear();
67  194 identityOperator = null;
68  194 setDefinitionByFormula = false;
69    }
70   
 
71  3629 toggle public boolean predicateExists(final Predicate predicate) {
72  3629 final PredicateDefinition definition = (PredicateDefinition) predicateDefinitions
73    .get(predicate);
74  3629 return null != definition;
75    }
76   
 
77  3411 toggle public boolean predicateExists(final String name, final int arguments) {
78  3411 final Predicate predicate = new Predicate(name, "" + arguments);
79  3411 return predicateExists(predicate);
80    }
81   
82    /**
83    * Add unknown predicate constant definition. If the predicate constant is already known a
84    * runtime exception is thrown.
85    *
86    * @param definition Predicate constant definition that is not already known. Must not be
87    * <code>null</code>.
88    * @throws IllegalArgumentException Predicate constant is already defined.
89    */
 
90  212 toggle public void add(final PredicateDefinition definition) {
91  212 final Predicate predicate = new Predicate(definition.getName(),
92    definition.getArgumentNumber());
93  212 if (predicateDefinitions.get(predicate) != null) {
94  0 throw new IllegalArgumentException(HigherLogicalErrors.PREDICATE_ALREADY_DEFINED_TEXT
95    + predicate);
96    }
97  212 predicateDefinitions.put(predicate, definition);
98    }
99   
100    /**
101    * Get predicate constant definition.
102    *
103    * @param predicate Get definition of this predicate.
104    * @return Definition.
105    */
 
106  359 toggle public PredicateDefinition get(final Predicate predicate) {
107  359 return (PredicateDefinition) predicateDefinitions.get(predicate);
108    }
109   
110    /**
111    * Get predicate constant definition.
112    *
113    * @param name Name of predicate.
114    * @param arguments Arguments of predicate.
115    * @return Definition. Might be <code>null</code>.
116    */
 
117  358 toggle public PredicateDefinition getPredicate(final String name, final int arguments) {
118  358 final Predicate predicate = new Predicate(name, "" + arguments);
119  358 return get(predicate);
120    }
121   
 
122  1550 toggle public boolean functionExists(final Function function) {
123  1550 final FunctionDefinition definition = (FunctionDefinition) functionDefinitions
124    .get(function);
125  1550 return null != definition;
126    }
127   
 
128  1442 toggle public boolean functionExists(final String name, final int arguments) {
129  1442 final Function function = new Function(name, "" + arguments);
130  1442 return functionExists(function);
131    }
132   
133    /**
134    * Add unknown function constant definition. If the function constant is already known a
135    * runtime exception is thrown.
136    *
137    * @param definition Function constant definition that is not already known. Must not be
138    * <code>null</code>.
139    * @throws IllegalArgumentException Function constant is already defined.
140    */
 
141  101 toggle public void add(final FunctionDefinition definition) {
142  101 final Function function = new Function(definition.getName(),
143    definition.getArgumentNumber());
144  101 if (functionDefinitions.get(function) != null) {
145  0 throw new IllegalArgumentException(HigherLogicalErrors.FUNCTION_ALREADY_DEFINED_TEXT
146    + function);
147    }
148  101 functionDefinitions.put(function, definition);
149    }
150   
151    /**
152    * Get function constant definition.
153    *
154    * @param function Get definition of this predicate.
155    * @return Definition. Might be <code>null</code>.
156    */
 
157  4 toggle public FunctionDefinition get(final Function function) {
158  4 return (FunctionDefinition) functionDefinitions.get(function);
159    }
160   
161    /**
162    * Get function constant definition.
163    *
164    * @param name Name of function.
165    * @param arguments Arguments of function.
166    * @return Definition. Might be <code>null</code>.
167    */
 
168  1 toggle public FunctionDefinition getFunction(final String name, final int arguments) {
169  1 final Function function = new Function(name, "" + arguments);
170  1 return get(function);
171    }
172   
 
173  0 toggle public boolean classOperatorExists() {
174  0 return setDefinitionByFormula;
175    }
176   
177    // /**
178    // * Set if the class operator is already defined.
179    // *
180    // * @param existence Class operator is defined.
181    // */
182    // TODO m31 20100820: write some tests that use this feature
183    // public void setClassOperatorExists(final boolean existence) {
184    // Trace.param(CLASS, this, "setClassOperatorExists", "existence", existence);
185    // setDefinitionByFormula = existence;
186    // }
187   
 
188  960 toggle public boolean identityOperatorExists() {
189  960 return this.identityOperator != null;
190    }
191   
 
192  790 toggle public String getIdentityOperator() {
193  790 return this.identityOperator;
194    }
195   
196    /**
197    * Set the identity operator.
198    *
199    * @param identityOperator Operator name. Might be <code>null</code>.
200    */
 
201  69 toggle public void setIdentityOperatorDefined(final String identityOperator) {
202  69 Trace.param(CLASS, this, "setIdentityOperatorDefined", "identityOperator", identityOperator);
203  69 this.identityOperator = identityOperator;
204    }
205   
206    }