Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart9.png 30% of files have more coverage
43   237   21   2,53
8   108   0,49   17
17     1,24  
1    
 
  DefaultExistenceChecker       Line # 38 43 21 83,8% 0.8382353
 
  (22)
 
1    /* $Id: DefaultExistenceChecker.java,v 1.1 2008/07/26 07:58:30 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.bo.module;
19   
20    import java.util.HashMap;
21    import java.util.Map;
22   
23    import org.qedeq.base.trace.Trace;
24    import org.qedeq.kernel.base.module.FunctionDefinition;
25    import org.qedeq.kernel.base.module.PredicateDefinition;
26    import org.qedeq.kernel.bo.logic.wf.ExistenceChecker;
27    import org.qedeq.kernel.bo.logic.wf.Function;
28    import org.qedeq.kernel.bo.logic.wf.HigherLogicalErrors;
29    import org.qedeq.kernel.bo.logic.wf.Predicate;
30   
31   
32    /**
33    * Checks if all predicate and function constants exist already.
34    *
35    * @version $Revision: 1.1 $
36    * @author Michael Meyling
37    */
 
38    public class DefaultExistenceChecker implements ExistenceChecker {
39   
40    /** This class. */
41    private static final Class CLASS = DefaultExistenceChecker.class;
42   
43    /** Maps {@link Predicate} identifiers to {@link PredicateDefinition}s. */
44    private final Map predicateDefinitions = new HashMap();
45   
46    /** Maps {@link Function} identifiers to {@link FunctionDefinition}s. */
47    private final Map functionDefinitions = new HashMap();
48   
49    /** Is the class operator already defined? */
50    private boolean setDefinitionByFormula;
51   
52    /** Is the identity operator already defined? */
53    private boolean identityOperatorDefined;
54   
55    /** Identity operator name. */
56    private String identityOperator;
57   
58   
59    /**
60    * Constructor.
61    */
 
62  63 toggle public DefaultExistenceChecker() {
63  63 clear();
64    }
65   
66    /**
67    * Empty all definitions.
68    */
 
69  125 toggle public void clear() {
70  125 Trace.trace(CLASS, this, "setClassOperatorExists", "clear");
71  125 predicateDefinitions.clear();
72  125 functionDefinitions.clear();
73  125 identityOperatorDefined = false;
74  125 identityOperator = null;
75  125 setDefinitionByFormula = false;
76    }
77   
78    /**
79    * Check if a predicate constant is already defined.
80    *
81    * @param predicate Predicate.
82    * @return Predicate is already defined.
83    */
 
84  168 toggle public boolean predicateExists(final Predicate predicate) {
85  168 final PredicateDefinition definition = (PredicateDefinition) predicateDefinitions
86    .get(predicate);
87  168 return null != definition;
88    }
89   
 
90  3172 toggle public boolean predicateExists(final String name, final int arguments) {
91  3172 final Predicate predicate = new Predicate(name, "" + arguments);
92  3172 final PredicateDefinition definition = (PredicateDefinition) predicateDefinitions
93    .get(predicate);
94  3172 return null != definition;
95    }
96   
97    /**
98    * Add unknown predicate constant definition. If the predicate constant is already known a
99    * runtime exception is thrown.
100    *
101    * @param definition Predicate constant definition that is not already known. Must not be
102    * <code>null</code>.
103    * @throws IllegalArgumentException Predicate constant is already defined.
104    */
 
105  168 toggle public void add(final PredicateDefinition definition) {
106  168 final Predicate predicate = new Predicate(definition.getName(),
107    definition.getArgumentNumber());
108  168 if (predicateDefinitions.get(predicate) != null) {
109  0 throw new IllegalArgumentException(HigherLogicalErrors.PREDICATE_ALREADY_DEFINED_TEXT
110    + predicate);
111    }
112  168 predicateDefinitions.put(predicate, definition);
113    }
114   
115    /**
116    * Get predicate constant definition.
117    *
118    * @param predicate Get definition of this predicate.
119    * @return Definition.
120    */
 
121  344 toggle public PredicateDefinition get(final Predicate predicate) {
122  344 return (PredicateDefinition) predicateDefinitions.get(predicate);
123    }
124   
125    /**
126    * Get predicate constant definition.
127    *
128    * @param name Name of predicate.
129    * @param arguments Arguments of predicate.
130    * @return Definition.
131    */
 
132  344 toggle public PredicateDefinition getPredicate(final String name, final int arguments) {
133  344 final Predicate predicate = new Predicate(name, "" + arguments);
134  344 return get(predicate);
135    }
136   
137    /**
138    * Check if a function constant is already defined.
139    *
140    * @param function Function.
141    * @return Function is already defined.
142    */
 
143  96 toggle public boolean functionExists(final Function function) {
144  96 final FunctionDefinition definition = (FunctionDefinition) functionDefinitions
145    .get(function);
146  96 return null != definition;
147    }
148   
 
149  1440 toggle public boolean functionExists(final String name, final int arguments) {
150  1440 final Function function = new Function(name, "" + arguments);
151  1440 final FunctionDefinition definition = (FunctionDefinition) functionDefinitions
152    .get(function);
153  1440 return null != definition;
154    }
155   
156    /**
157    * Add unknown function constant definition. If the function constant is already known a
158    * runtime exception is thrown.
159    *
160    * @param definition Function constant definition that is not already known. Must not be
161    * <code>null</code>.
162    * @throws IllegalArgumentException Function constant is already defined.
163    */
 
164  96 toggle public void add(final FunctionDefinition definition) {
165  96 final Function function = new Function(definition.getName(),
166    definition.getArgumentNumber());
167  96 if (functionDefinitions.get(function) != null) {
168  0 throw new IllegalArgumentException(HigherLogicalErrors.FUNCTION_ALREADY_DEFINED_TEXT
169    + function);
170    }
171  96 functionDefinitions.put(function, definition);
172    }
173   
174    /**
175    * Get function constant definition.
176    *
177    * @param function Get definition of this predicate.
178    * @return Definition.
179    */
 
180  0 toggle public FunctionDefinition get(final Function function) {
181  0 return (FunctionDefinition) functionDefinitions.get(function);
182    }
183   
184    /**
185    * Get function constant definition.
186    *
187    * @param name Name of function.
188    * @param arguments Arguments of function.
189    * @return Definition.
190    */
 
191  0 toggle public FunctionDefinition getFunction(final String name, final int arguments) {
192  0 final Function function = new Function(name, "" + arguments);
193  0 return get(function);
194    }
195   
 
196  228 toggle public boolean classOperatorExists() {
197  228 return setDefinitionByFormula;
198    }
199   
200    /**
201    * Set if the class operator is already defined.
202    *
203    * @param existence Class operator is defined.
204    */
 
205  68 toggle public void setClassOperatorExists(final boolean existence) {
206  68 Trace.param(CLASS, this, "setClassOperatorExists", "existence", existence);
207  68 setDefinitionByFormula = existence;
208    }
209   
 
210  1520 toggle public boolean equalityOperatorExists() {
211  1520 return identityOperatorDefined;
212    }
213   
214    /**
215    * Set the identity operator.
216    *
217    * @param defined Is the operator defined?
218    * @param identityOperator Operator name.
219    */
 
220  79 toggle public void setIdentityOperatorDefined(final boolean defined, final String identityOperator) {
221  79 Trace.param(CLASS, this, "setIdentityOperatorDefined", "defined", defined);
222  79 this.identityOperatorDefined = defined;
223  79 if (defined) {
224  37 this.identityOperator = identityOperator;
225    } else {
226  42 this.identityOperator = null;
227    }
228    }
229   
 
230  674 toggle public String getIdentityOperator() {
231  674 if (!equalityOperatorExists()) {
232  0 return null;
233    }
234  674 return this.identityOperator;
235    }
236   
237    }