Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 234   Methods: 17
NCLOC: 105   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultExistenceChecker.java 62,5% 86% 88,2% 83,8%
coverage coverage
 1    /* $Id: DefaultExistenceChecker.java,v 1.1 2008/01/26 12:39:09 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.logic;
 19   
 20    import java.util.HashMap;
 21    import java.util.Map;
 22   
 23    import org.qedeq.kernel.base.module.FunctionDefinition;
 24    import org.qedeq.kernel.base.module.PredicateDefinition;
 25    import org.qedeq.kernel.bo.control.HigherLogicalErrors;
 26    import org.qedeq.kernel.trace.Trace;
 27   
 28   
 29    /**
 30    * Checks if all predicate and function constants exist already.
 31    *
 32    * @version $Revision: 1.1 $
 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    /** Is the identity operator already defined? */
 50    private boolean identityOperatorDefined;
 51   
 52    /** Identity operator name. */
 53    private String identityOperator;
 54   
 55   
 56    /**
 57    * Constructor.
 58    */
 59  59 public DefaultExistenceChecker() {
 60  59 clear();
 61    }
 62   
 63    /**
 64    * Empty all definitions.
 65    */
 66  118 public void clear() {
 67  118 Trace.trace(CLASS, this, "setClassOperatorExists", "clear");
 68  118 predicateDefinitions.clear();
 69  118 functionDefinitions.clear();
 70  118 identityOperatorDefined = false;
 71  118 identityOperator = null;
 72  118 setDefinitionByFormula = false;
 73    }
 74   
 75    /**
 76    * Check if a predicate constant is already defined.
 77    *
 78    * @param predicate Predicate.
 79    * @return Predicate is already defined.
 80    */
 81  164 public boolean predicateExists(final Predicate predicate) {
 82  164 final PredicateDefinition definition = (PredicateDefinition) predicateDefinitions
 83    .get(predicate);
 84  164 return null != definition;
 85    }
 86   
 87  3139 public boolean predicateExists(final String name, final int arguments) {
 88  3139 final Predicate predicate = new Predicate(name, "" + arguments);
 89  3139 final PredicateDefinition definition = (PredicateDefinition) predicateDefinitions
 90    .get(predicate);
 91  3139 return null != definition;
 92    }
 93   
 94    /**
 95    * Add unknown predicate constant definition. If the predicate constant is already known a
 96    * runtime exception is thrown.
 97    *
 98    * @param definition Predicate constant definition that is not already known. Must not be
 99    * <code>null</code>.
 100    * @throws IllegalArgumentException Predicate constant is already defined.
 101    */
 102  164 public void add(final PredicateDefinition definition) {
 103  164 final Predicate predicate = new Predicate(definition.getName(),
 104    definition.getArgumentNumber());
 105  164 if (predicateDefinitions.get(predicate) != null) {
 106  0 throw new IllegalArgumentException(HigherLogicalErrors.PREDICATE_ALREADY_DEFINED_TEXT
 107    + predicate);
 108    }
 109  164 predicateDefinitions.put(predicate, definition);
 110    }
 111   
 112    /**
 113    * Get predicate constant definition.
 114    *
 115    * @param predicate Get definition of this predicate.
 116    * @return Definition.
 117    */
 118  354 public PredicateDefinition get(final Predicate predicate) {
 119  354 return (PredicateDefinition) predicateDefinitions.get(predicate);
 120    }
 121   
 122    /**
 123    * Get predicate constant definition.
 124    *
 125    * @param name Name of predicate.
 126    * @param arguments Arguments of predicate.
 127    * @return Definition.
 128    */
 129  354 public PredicateDefinition getPredicate(final String name, final int arguments) {
 130  354 final Predicate predicate = new Predicate(name, "" + arguments);
 131  354 return get(predicate);
 132    }
 133   
 134    /**
 135    * Check if a function constant is already defined.
 136    *
 137    * @param function Function.
 138    * @return Function is already defined.
 139    */
 140  96 public boolean functionExists(final Function function) {
 141  96 final FunctionDefinition definition = (FunctionDefinition) functionDefinitions
 142    .get(function);
 143  96 return null != definition;
 144    }
 145   
 146  1440 public boolean functionExists(final String name, final int arguments) {
 147  1440 final Function function = new Function(name, "" + arguments);
 148  1440 final FunctionDefinition definition = (FunctionDefinition) functionDefinitions
 149    .get(function);
 150  1440 return null != definition;
 151    }
 152   
 153    /**
 154    * Add unknown function constant definition. If the function constant is already known a
 155    * runtime exception is thrown.
 156    *
 157    * @param definition Function constant definition that is not already known. Must not be
 158    * <code>null</code>.
 159    * @throws IllegalArgumentException Function constant is already defined.
 160    */
 161  96 public void add(final FunctionDefinition definition) {
 162  96 final Function function = new Function(definition.getName(),
 163    definition.getArgumentNumber());
 164  96 if (functionDefinitions.get(function) != null) {
 165  0 throw new IllegalArgumentException(HigherLogicalErrors.FUNCTION_ALREADY_DEFINED_TEXT
 166    + function);
 167    }
 168  96 functionDefinitions.put(function, definition);
 169    }
 170   
 171    /**
 172    * Get function constant definition.
 173    *
 174    * @param function Get definition of this predicate.
 175    * @return Definition.
 176    */
 177  0 public FunctionDefinition get(final Function function) {
 178  0 return (FunctionDefinition) functionDefinitions.get(function);
 179    }
 180   
 181    /**
 182    * Get function constant definition.
 183    *
 184    * @param name Name of function.
 185    * @param arguments Arguments of function.
 186    * @return Definition.
 187    */
 188  0 public FunctionDefinition getFunction(final String name, final int arguments) {
 189  0 final Function function = new Function(name, "" + arguments);
 190  0 return get(function);
 191    }
 192   
 193  230 public boolean classOperatorExists() {
 194  230 return setDefinitionByFormula;
 195    }
 196   
 197    /**
 198    * Set if the class operator is already defined.
 199    *
 200    * @param existence Class operator is defined.
 201    */
 202  65 public void setClassOperatorExists(final boolean existence) {
 203  65 Trace.param(CLASS, this, "setClassOperatorExists", "existence", existence);
 204  65 setDefinitionByFormula = existence;
 205    }
 206   
 207  1504 public boolean equalityOperatorExists() {
 208  1504 return identityOperatorDefined;
 209    }
 210   
 211    /**
 212    * Set the identity operator.
 213    *
 214    * @param defined Is the operator defined?
 215    * @param identityOperator Operator name.
 216    */
 217  72 public void setIdentityOperatorDefined(final boolean defined, final String identityOperator) {
 218  72 Trace.param(CLASS, this, "setIdentityOperatorDefined", "defined", defined);
 219  72 this.identityOperatorDefined = defined;
 220  72 if (defined) {
 221  35 this.identityOperator = identityOperator;
 222    } else {
 223  37 this.identityOperator = null;
 224    }
 225    }
 226   
 227  668 public String getIdentityOperator() {
 228  668 if (!equalityOperatorExists()) {
 229  0 return null;
 230    }
 231  668 return this.identityOperator;
 232    }
 233   
 234    }