Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 127   Methods: 6
NCLOC: 45   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ModuleLabels.java 75% 81,2% 83,3% 80,8%
coverage coverage
 1    /* $Id: ModuleLabels.java,v 1.1 2008/03/27 05:16:25 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.common;
 19   
 20    import java.util.HashMap;
 21    import java.util.Map;
 22   
 23    import org.qedeq.kernel.dto.module.NodeVo;
 24   
 25    /**
 26    * Maps labels of an QEDEQ module to their nodes. Knows all label names.
 27    *
 28    * @version $Revision: 1.1 $
 29    * @author Michael Meyling
 30    */
 31    public final class ModuleLabels {
 32   
 33    /** Maps labels to business objects. */
 34    private final Map label2Bo;
 35   
 36    /** Maps labels to context of business objects. */
 37    private final Map label2Context;
 38   
 39    /**
 40    * Constructs a new empty module label list.
 41    */
 42  154 public ModuleLabels() {
 43  154 label2Bo = new HashMap();
 44  154 label2Context = new HashMap();
 45    }
 46   
 47    /**
 48    * Add node with certain id.
 49    *
 50    * @param node For this node.
 51    * @param context With this context.
 52    * @throws IllegalModuleDataException The <code>id</code> already exists (perhaps as a label)
 53    * or is <code>null</code>.
 54    */
 55  1358 public final void addNode(final ModuleContext context, final NodeVo node)
 56    throws IllegalModuleDataException {
 57    // don't forget to use the copy constructor because the context could change!
 58  1358 final ModuleContext con = new ModuleContext(context);
 59  1358 if (null == node.getId()) {
 60  0 throw new IllegalModuleDataException(10001, "An id was not defined.", con, null,
 61    null); // LATER mime 20071026: organize exception codes
 62    }
 63  1358 checkLabelIntern(con, node.getId());
 64  1352 label2Context.put(node.getId(), con);
 65  1352 label2Bo.put(node.getId(), node);
 66    }
 67   
 68    /**
 69    * Add unique label for module.
 70    *
 71    * @param label Add this label.
 72    * @param context With this context.
 73    * @throws IllegalModuleDataException The <code>id</code> already exists or is
 74    * <code>null</code>.
 75    */
 76  141 public final void addLabel(final ModuleContext context, final String label)
 77    throws IllegalModuleDataException {
 78    // don't forget to use the copy constructor because the context could change!
 79  141 final ModuleContext con = new ModuleContext(context);
 80  141 checkLabelIntern(con, label);
 81  141 label2Context.put(label, con);
 82    }
 83   
 84    /**
 85    * Check that label doesn't exist.
 86    *
 87    * @param label Check this label.
 88    * @param context With this context.
 89    * @throws IllegalModuleDataException The <code>id</code> already exists or is
 90    * <code>null</code>.
 91    */
 92  0 public final void checkLabel(final ModuleContext context, final String label)
 93    throws IllegalModuleDataException {
 94    // don't forget to use the copy constructor because the context could change!
 95  0 final ModuleContext con = new ModuleContext(context);
 96  0 checkLabelIntern(con, label);
 97    }
 98   
 99    /**
 100    * Check that label doesn't exist.
 101    *
 102    * @param label Check this label.
 103    * @param context With this context (already copied).
 104    * @throws IllegalModuleDataException The <code>id</code> already exists or is
 105    * <code>null</code>.
 106    */
 107  1499 private final void checkLabelIntern(final ModuleContext context, final String label)
 108    throws IllegalModuleDataException {
 109  1499 if (label2Context.containsKey(label)) {
 110    // LATER mime 20071026: organize exception codes
 111  6 throw new IllegalModuleDataException(10002, "Id or label \"" + label
 112    + "\" defined more than once.", context,
 113    (ModuleContext) label2Context.get(label), null);
 114    }
 115    }
 116   
 117    /**
 118    * Get node for given id.
 119    *
 120    * @param id Label to search node for.
 121    * @return Node for given label. Maybe <code>null</code>.
 122    */
 123  5 public final NodeVo getNode(final String id) {
 124  5 return (NodeVo) label2Bo.get(id);
 125    }
 126   
 127    }