%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.configuration.MapConfiguration |
|
|
1 | /* |
|
2 | * Copyright 2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | ||
17 | package org.apache.commons.configuration; |
|
18 | ||
19 | import java.util.Iterator; |
|
20 | import java.util.List; |
|
21 | import java.util.Map; |
|
22 | ||
23 | /** |
|
24 | * A Map based Configuration. |
|
25 | * |
|
26 | * @author Emmanuel Bourg |
|
27 | * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $ |
|
28 | * @since 1.1 |
|
29 | */ |
|
30 | public class MapConfiguration extends AbstractConfiguration |
|
31 | { |
|
32 | /** The Map decorated by this configuration. */ |
|
33 | protected Map map; |
|
34 | ||
35 | /** |
|
36 | * Create a Configuration decorator around the specified Map. The map is |
|
37 | * used to store the configuration properties, any change will also affect |
|
38 | * the Map. |
|
39 | * |
|
40 | * @param map |
|
41 | */ |
|
42 | public MapConfiguration(Map map) |
|
43 | 345 | { |
44 | 345 | this.map = map; |
45 | 345 | } |
46 | ||
47 | /** |
|
48 | * Return the Map decorated by this configuration. |
|
49 | */ |
|
50 | public Map getMap() |
|
51 | { |
|
52 | 23 | return map; |
53 | } |
|
54 | ||
55 | public Object getProperty(String key) |
|
56 | { |
|
57 | 3225 | Object value = map.get(key); |
58 | 3225 | if (value instanceof String) |
59 | { |
|
60 | 1523 | List list = PropertyConverter.split((String) value, getDelimiter()); |
61 | 1523 | return list.size() > 1 ? list : value; |
62 | } |
|
63 | else |
|
64 | { |
|
65 | 1702 | return value; |
66 | } |
|
67 | } |
|
68 | ||
69 | protected void addPropertyDirect(String key, Object obj) |
|
70 | { |
|
71 | 23 | map.put(key, obj); |
72 | 23 | } |
73 | ||
74 | public boolean isEmpty() |
|
75 | { |
|
76 | 46 | return map.isEmpty(); |
77 | } |
|
78 | ||
79 | public boolean containsKey(String key) |
|
80 | { |
|
81 | 115 | return map.containsKey(key); |
82 | } |
|
83 | ||
84 | public void clearProperty(String key) |
|
85 | { |
|
86 | 23 | map.remove(key); |
87 | 23 | } |
88 | ||
89 | public Iterator getKeys() |
|
90 | { |
|
91 | 55 | return map.keySet().iterator(); |
92 | } |
|
93 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |