Clover Coverage Report - XWiki Commons - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 17:13:48 CET
../../../../img/srcFileCovDistChart7.png 44% of files have more coverage
16   118   10   2
4   65   0.62   8
8     1.25  
1    
 
  MemoryConfigurationSource       Line # 43 16 0% 10 10 64.3% 0.64285713
 
No Tests
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.configuration.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24    import java.util.Map;
25    import java.util.concurrent.ConcurrentHashMap;
26   
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31   
32    /**
33    * Runtime configuration source stored in memory.
34    * <p>
35    * Can be modified by lookuping the component and using {@link MemoryConfigurationSource#setProperty(String, Object)}.
36    *
37    * @version $Id: 90cccc2f6b20870b7009e3921b86ae845d470d64 $
38    * @since 3.5M1
39    */
40    @Component
41    @Singleton
42    @Named("memory")
 
43    public class MemoryConfigurationSource extends AbstractConfigurationSource
44    {
45    /**
46    * The properties.
47    */
48    private Map<String, Object> properties = new ConcurrentHashMap<String, Object>();
49   
50    /**
51    * @param key the key for the value to add to the configuration
52    * @param value the value to add in the configuration
53    */
 
54  1 toggle public void setProperty(String key, Object value)
55    {
56  1 this.properties.put(key, value);
57    }
58   
59    /**
60    * @param key the key associated to the property to remove
61    */
 
62  0 toggle public void removeProperty(String key)
63    {
64  0 this.properties.remove(key);
65    }
66   
 
67  70 toggle @Override
68    public <T> T getProperty(String key, T defaultValue)
69    {
70  70 T value;
71   
72  70 if (this.properties.containsKey(key)) {
73  1 value = (T) this.properties.get(key);
74    } else {
75  69 value = defaultValue;
76    }
77   
78  70 return value;
79    }
80   
 
81  33 toggle @Override
82    public <T> T getProperty(String key, Class<T> valueClass)
83    {
84  33 T value;
85   
86  33 if (this.properties.containsKey(key)) {
87  0 value = (T) this.properties.get(key);
88    } else {
89  33 value = getDefault(valueClass);
90    }
91   
92  33 return value;
93    }
94   
 
95  75 toggle @Override
96    public <T> T getProperty(String key)
97    {
98  75 return (T) this.properties.get(key);
99    }
100   
 
101  0 toggle @Override
102    public List<String> getKeys()
103    {
104  0 return new ArrayList<String>(this.properties.keySet());
105    }
106   
 
107  0 toggle @Override
108    public boolean containsKey(String key)
109    {
110  0 return this.properties.containsKey(key);
111    }
112   
 
113  0 toggle @Override
114    public boolean isEmpty()
115    {
116  0 return this.properties.isEmpty();
117    }
118    }