Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../img/srcFileCovDistChart8.png 47% of files have more coverage
16   127   8   2,67
4   45   0,5   6
6     1,33  
1    
 
  ModuleLabels       Line # 31 16 8 80,8% 0.8076923
 
  (36)
 
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  125 toggle public ModuleLabels() {
43  125 label2Bo = new HashMap();
44  125 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  1047 toggle 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  1047 final ModuleContext con = new ModuleContext(context);
59  1047 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  1047 checkLabelIntern(con, node.getId());
64  1044 label2Context.put(node.getId(), con);
65  1044 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  114 toggle 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  114 final ModuleContext con = new ModuleContext(context);
80  114 checkLabelIntern(con, label);
81  114 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 toggle 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  1161 toggle private final void checkLabelIntern(final ModuleContext context, final String label)
108    throws IllegalModuleDataException {
109  1161 if (label2Context.containsKey(label)) {
110    // LATER mime 20071026: organize exception codes
111  3 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  80 toggle public final NodeVo getNode(final String id) {
124  80 return (NodeVo) label2Bo.get(id);
125    }
126   
127    }