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