Clover icon

sunshower-base

  1. Project Clover database Fri Apr 6 2018 03:41:27 UTC
  2. Package io.sunshower.common.configuration

File MapConfigurationSource.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
50% of files have more coverage

Code metrics

8
26
12
1
85
69
17
0.65
2.17
12
1.42

Classes

Class Line # Actions
MapConfigurationSource 6 26 17
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.common.configuration;
2   
3    import java.util.Map;
4    import java.util.NoSuchElementException;
5   
 
6    public class MapConfigurationSource implements ConfigurationSource {
7   
8    final Map<String, String> source;
9   
 
10  0 toggle public MapConfigurationSource(Map<String, String> source) {
11  0 this.source = source;
12    }
13   
 
14  0 toggle @Override
15    public void stop() throws Exception {}
16   
 
17  0 toggle @Override
18    public void start() throws Exception {}
19   
 
20  0 toggle @Override
21    public String get(ValueHolder v, boolean fail) {
22  0 return get(v.value(), fail);
23    }
24   
 
25  0 toggle @Override
26    public String get(String key, boolean fail) {
27  0 final String result = source.get(key);
28  0 if (result != null) {
29  0 return result;
30    }
31  0 if (fail) {
32  0 throw new NoSuchElementException(createMessage(key));
33    }
34  0 return null;
35    }
36   
 
37  0 toggle @Override
38    public String get(String key) {
39  0 return null;
40    }
41   
 
42  0 toggle @Override
43    public String get(String key, String defaultValue) {
44  0 final String result = this.source.get(key);
45  0 if (result == null) {
46  0 return defaultValue;
47    }
48  0 return result;
49    }
50   
 
51  0 toggle @Override
52    public String set(String key, String value) {
53  0 return set(key, value, false);
54    }
55   
 
56  0 toggle @Override
57    public String set(String key, String value, boolean override) {
58  0 final String v = source.get(key);
59  0 if (v == null || override) {
60  0 source.put(key, value);
61  0 return value;
62    }
63  0 return null;
64    }
65   
 
66  0 toggle @Override
67    public boolean isSecure() {
68  0 return true;
69    }
70   
 
71  0 toggle @Override
72    @SuppressWarnings("unchecked")
73    public <T> T unwrap(Class<T> type) {
74  0 return (T) source;
75    }
76   
 
77  0 toggle private String createMessage(String key) {
78  0 final StringBuilder b = new StringBuilder();
79   
80  0 b.append("Failed to find value for key '").append(key).append('\'');
81  0 b.append(" Known pairs: ");
82  0 b.append(source.toString());
83  0 return b.toString();
84    }
85    }