Clover icon

sunshower-base

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

File LazyPropertyAware.java

 

Coverage histogram

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

Code metrics

12
18
6
1
68
59
15
0.83
3
6
2.5

Classes

Class Line # Actions
LazyPropertyAware 13 18 15
0.944444494.4%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    package io.sunshower.reflect.incant;
2   
3    import io.sunshower.lang.PropertyAware;
4    import io.sunshower.lang.tuple.Pair;
5    import java.util.Collections;
6    import java.util.HashMap;
7    import java.util.Map;
8    import java.util.Set;
9    import java.util.stream.Collectors;
10    import javax.annotation.concurrent.ThreadSafe;
11   
12    @ThreadSafe
 
13    public class LazyPropertyAware implements PropertyAware {
14   
15    private Map<String, String> properties;
16   
 
17  3 toggle @Override
18    public boolean hasProperty(String key) {
19  3 if (properties == null || properties.isEmpty()) {
20  2 return false;
21    }
22  1 return properties.containsKey(key);
23    }
24   
 
25  2 toggle @Override
26    public String getProperty(String key) {
27  2 if (properties == null) {
28  1 return null;
29    }
30  1 return properties.get(key);
31    }
32   
 
33  2 toggle @Override
34    public Set<Pair<String, String>> getProperties() {
35  2 if (properties == null || properties.isEmpty()) {
36  1 return Collections.emptySet();
37    }
38  1 return properties
39    .entrySet()
40    .stream()
41    .map(f -> Pair.of(f.getKey(), f.getValue()))
42    .collect(Collectors.toSet());
43    }
44   
 
45  4 toggle @Override
46    public boolean addProperty(String key, String value) {
47  4 check();
48  4 return properties.put(key, value) == null;
49    }
50   
 
51  2 toggle @Override
52    public String removeProperty(String key) {
53  2 if (properties == null || properties.isEmpty()) {
54  1 return null;
55    }
56  1 return properties.remove(key);
57    }
58   
 
59  4 toggle private void check() {
60  4 if (properties == null) {
61  4 synchronized (this) {
62  4 if (properties == null) {
63  4 properties = new HashMap<>();
64    }
65    }
66    }
67    }
68    }