Clover Coverage Report - Kuali Student 1.1.0-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 15 2011 04:04:07 EST
../../../../../../img/srcFileCovDistChart9.png 28% of files have more coverage
11   110   9   1.38
2   38   0.82   8
8     1.12  
1    
 
  ContextRegistry       Line # 28 11 0% 9 2 90.5% 0.9047619
 
  (104)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.core.statement.naturallanguage;
17   
18    import java.util.ArrayList;
19    import java.util.HashMap;
20    import java.util.List;
21    import java.util.Map;
22   
23   
24    /**
25    * This class is a registry of template contexts which the requirement
26    * component translator uses to generate natural language.
27    */
 
28    public class ContextRegistry<T extends Context<?>> {
29   
30    /** Registry context map */
31    private Map<String, List<T>> registry = new HashMap<String, List<T>>();
32   
33    /**
34    * Constructor.
35    */
 
36  18 toggle public ContextRegistry() {
37    }
38   
39    /**
40    * Constructor. Adds a context registry as a map.
41    *
42    * @param registry Context registry
43    */
 
44  12 toggle public ContextRegistry(final Map<String, List<T>> registry) {
45  12 this.registry = registry;
46    }
47   
48    /**
49    * Adds a context to the registry. Key is usually a
50    * <@link {@link ReqComponentType} key.
51    *
52    * @param key Context key
53    * @param context Context
54    */
 
55  81 toggle public void add(final String key, final T context) {
56  81 if(this.registry.containsKey(key)) {
57  11 this.registry.get(key).add(context);
58    } else {
59  70 List<T> list = new ArrayList<T>();
60  70 list.add(context);
61  70 this.registry.put(key, list);
62    }
63    }
64   
65    /**
66    * Gets a context from the registry. Key is usually a
67    * <@link {@link ReqComponentType} key.
68    *
69    * @param key Context key
70    * @return A context
71    */
 
72  140 toggle public List<T> get(final String key) {
73  140 return this.registry.get(key);
74    }
75   
76    /**
77    * Returns true if a context exists for <code>key</code>; otherwise false.
78    *
79    * @param key Context key
80    * @return True if a context exists otherwise false
81    */
 
82  5 toggle public boolean containsKey(final String key) {
83  5 return this.registry.containsKey(key);
84    }
85   
86    /**
87    * Remove a context from the registry. Key is usually a
88    * <@link {@link ReqComponentType} key.
89    *
90    * @param key
91    * @return
92    */
 
93  2 toggle public List<T> remove(final String key) {
94  2 return this.registry.remove(key);
95    }
96   
97    /**
98    * Returns the number of keys of the registry.
99    *
100    * @return Number of keys in the registry
101    */
 
102  1 toggle public int size() {
103  1 return this.registry.size();
104    }
105   
 
106  0 toggle @Override
107    public String toString() {
108  0 return this.registry.toString();
109    }
110    }