Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 153   Methods: 8
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
QedeqBoDuplicateLanguageChecker.java 75% 87% 87,5% 84,6%
coverage coverage
 1    /* $Id: QedeqBoDuplicateLanguageChecker.java,v 1.4 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.control;
 19   
 20    import java.util.HashMap;
 21    import java.util.Map;
 22   
 23    import org.qedeq.kernel.base.module.Latex;
 24    import org.qedeq.kernel.base.module.LatexList;
 25    import org.qedeq.kernel.base.module.Qedeq;
 26    import org.qedeq.kernel.bo.module.ModuleAddress;
 27    import org.qedeq.kernel.bo.module.ModuleContext;
 28    import org.qedeq.kernel.bo.module.ModuleDataException;
 29    import org.qedeq.kernel.bo.module.QedeqBo;
 30    import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor;
 31    import org.qedeq.kernel.bo.visitor.QedeqNotNullTraverser;
 32   
 33   
 34    /**
 35    * Checks if all formulas of a QEDEQ module are well formed.
 36    *
 37    * @version $Revision: 1.4 $
 38    * @author Michael Meyling
 39    */
 40    public final class QedeqBoDuplicateLanguageChecker extends AbstractModuleVisitor {
 41   
 42    /** QEDEQ module input object. */
 43    private final QedeqBo original;
 44   
 45    /** Current context during creation. */
 46    private final QedeqNotNullTraverser traverser;
 47   
 48    /**
 49    * Constructor.
 50    *
 51    * @param globalContext Module location information.
 52    * @param qedeq BO QEDEQ module object.
 53    */
 54  305 private QedeqBoDuplicateLanguageChecker(final ModuleAddress globalContext,
 55    final QedeqBo qedeq) {
 56  305 traverser = new QedeqNotNullTraverser(globalContext, this);
 57  305 original = qedeq;
 58    }
 59   
 60    /**
 61    * Checks if all formulas of a QEDEQ module are well formed.
 62    *
 63    * @param globalContext Module location information.
 64    * @param qedeq Basic QEDEQ module object.
 65    * @throws ModuleDataException Major problem occurred.
 66    */
 67  305 public static void check(final ModuleAddress globalContext, final QedeqBo qedeq)
 68    throws ModuleDataException {
 69  305 final QedeqBoDuplicateLanguageChecker checker
 70    = new QedeqBoDuplicateLanguageChecker(globalContext, qedeq);
 71  305 checker.check();
 72    }
 73   
 74  305 private final void check() throws ModuleDataException {
 75  305 traverser.accept(original.getQedeq());
 76    }
 77   
 78  9423 public final void visitEnter(final LatexList list) throws ModuleDataException {
 79  9423 if (list == null) {
 80  0 return;
 81    }
 82  9423 final String context = getCurrentContext().getLocationWithinModule();
 83  9423 final Map languages = new HashMap();
 84  9423 for (int i = 0; i < list.size(); i++) {
 85  16426 final Latex latex = list.get(i);
 86  16426 setLocationWithinModule(context + ".get(" + i + ")");
 87  16426 if (latex == null) {
 88  0 throw new LatexListDataException(1000, "Null pointer not permitted.",
 89    getCurrentContext());
 90    }
 91  16426 if (languages.containsKey(latex.getLanguage())) {
 92  1 throw new LatexListDataException(1001, "Language entry exists already",
 93    getCurrentContext(), (ModuleContext) languages.get(latex.getLanguage()));
 94    }
 95  16425 languages.put(list.get(i).getLanguage(), getCurrentContext());
 96    }
 97  9422 setLocationWithinModule(context);
 98  9422 traverser.setBlocked(true);
 99    }
 100    /*
 101    try {
 102    if (latexList.get(i) == null) {
 103    throw new NullPointerListEntryException(1000, "Null pointer not permitted.");
 104    }
 105    for (int j = 0; j < list.size(); j++) {
 106    if ((list.get(j)).getLanguage().equals(latexList.get(i).getLanguage())) {
 107    throw new DuplicateLanguageEntryException(1001,
 108    "Language entry exists already", i);
 109    }
 110    }
 111    list.add(create(latexList.get(i)));
 112    } catch (NullPointerListEntryException e) {
 113    throw new IllegalModuleDataException(e.getErrorCode(),
 114    e.getMessage(), new ModuleContext(getCurrentContext()), e);
 115    } catch (DuplicateLanguageEntryException e) {
 116    throw new IllegalModuleDataException(e.getErrorCode(), e.getMessage(),
 117    new ModuleContext(getCurrentContext()), new ModuleContext(getCurrentContext(),
 118    context + ".get(" + (e.getIndex() + 1) + ")"), e);
 119    }
 120   
 121    */
 122  9422 public final void visitLeave(final LatexList list) {
 123  9422 traverser.setBlocked(false);
 124    }
 125   
 126    /**
 127    * Set location information where are we within the original module.
 128    *
 129    * @param locationWithinModule Location within module.
 130    */
 131  25848 public void setLocationWithinModule(final String locationWithinModule) {
 132  25848 getCurrentContext().setLocationWithinModule(locationWithinModule);
 133    }
 134   
 135    /**
 136    * Get current context within original.
 137    *
 138    * @return Current context.
 139    */
 140  51697 public final ModuleContext getCurrentContext() {
 141  51697 return traverser.getCurrentContext();
 142    }
 143   
 144    /**
 145    * Get original QEDEQ module.
 146    *
 147    * @return Original QEDEQ module.
 148    */
 149  0 protected final Qedeq getQedeqOriginal() {
 150  0 return original.getQedeq();
 151    }
 152   
 153    }