1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.configuration.internal

File AbstractCompositeConfigurationSource.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

14
38
6
1
135
85
13
0.34
6.33
6
2.17

Classes

Class Line # Actions
AbstractCompositeConfigurationSource 36 38 0% 13 0
1.0100%
 

Contributing tests

This file is covered by 11 tests. .

Source view

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.LinkedHashSet;
24    import java.util.List;
25    import java.util.Set;
26   
27    import org.xwiki.configuration.ConfigurationSource;
28   
29    /**
30    * Base class for composing (aka chaining) several Configuration Sources. The order of sources is important. Sources
31    * located before other sources take priority.
32    *
33    * @version $Id: 63b6eefae467d8ca8b0e47b611b8d23ed46978d7 $
34    * @since 7.4M1
35    */
 
36    public abstract class AbstractCompositeConfigurationSource extends AbstractConfigurationSource
37    implements Iterable<ConfigurationSource>
38    {
 
39  423791 toggle @Override
40    public boolean containsKey(String key)
41    {
42  423783 boolean result = false;
43   
44  423814 for (ConfigurationSource source : this) {
45  519541 if (source.containsKey(key)) {
46  532 result = true;
47  532 break;
48    }
49    }
50   
51  423785 return result;
52    }
53   
 
54  13444 toggle @Override
55    public <T> T getProperty(String key)
56    {
57  13444 T result = null;
58   
59  13429 for (ConfigurationSource source : this) {
60  39989 if (source.containsKey(key)) {
61  80 result = source.<T>getProperty(key);
62  80 break;
63    }
64    }
65   
66  13446 return result;
67    }
68   
 
69  18219 toggle @Override
70    public <T> T getProperty(String key, Class<T> valueClass)
71    {
72  18218 T result = null;
73   
74  18216 for (ConfigurationSource source : this) {
75  53736 if (source.containsKey(key)) {
76  5 result = source.getProperty(key, valueClass);
77  5 break;
78    }
79    }
80   
81    // List and Properties must return empty collections and not null values.
82  18219 if (result == null) {
83  18213 result = getDefault(valueClass);
84    }
85   
86  18218 return result;
87    }
88   
 
89  181118 toggle @Override
90    public <T> T getProperty(String key, T defaultValue)
91    {
92  181100 T result = null;
93   
94  181091 for (ConfigurationSource source : this) {
95  361701 if (source.containsKey(key)) {
96  1067 result = source.<T>getProperty(key, defaultValue);
97  1067 break;
98    }
99    }
100   
101  181143 if (result == null) {
102  180071 result = defaultValue;
103    }
104   
105  181138 return result;
106    }
107   
 
108  40 toggle @Override
109    public List<String> getKeys()
110    {
111    // We use a linked hash set in order to keep the keys in the order in which they were defined in the sources.
112  40 Set<String> keys = new LinkedHashSet<String>();
113   
114  40 for (ConfigurationSource source : this) {
115  53 keys.addAll(source.getKeys());
116    }
117   
118  40 return new ArrayList<String>(keys);
119    }
120   
 
121  5 toggle @Override
122    public boolean isEmpty()
123    {
124  5 boolean result = true;
125   
126  5 for (ConfigurationSource source : this) {
127  6 if (!source.isEmpty()) {
128  3 result = false;
129  3 break;
130    }
131    }
132   
133  5 return result;
134    }
135    }