Clover icon

sunshower-base

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

File MapAdapter.java

 

Coverage histogram

../../../../img/srcFileCovDistChart3.png
45% of files have more coverage

Code metrics

4
18
4
3
61
50
6
0.33
4.5
1.33
1.5

Classes

Class Line # Actions
MapAdapter 9 18 6
0.3076923230.8%
MapAdapter.AdaptedMap 11 0 0
-1.0 -
MapAdapter.AdaptedEntry 17 0 0
-1.0 -
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package io.sunshower.common.rs;
2   
3    import java.util.*;
4    import java.util.Map.Entry;
5    import javax.xml.bind.annotation.*;
6    import javax.xml.bind.annotation.adapters.XmlAdapter;
7    import org.eclipse.persistence.oxm.annotations.XmlVariableNode;
8   
 
9    public class MapAdapter extends XmlAdapter<MapAdapter.AdaptedMap, Map<String, String>> {
10   
 
11    public static class AdaptedMap {
12   
13    @XmlVariableNode("key")
14    List<AdaptedEntry> entries = new ArrayList<AdaptedEntry>();
15    }
16   
 
17    public static class AdaptedEntry {
18   
19    @XmlTransient public String key;
20   
21    @XmlValue public String value;
22    }
23   
 
24  0 toggle @Override
25    public AdaptedMap marshal(Map<String, String> map) throws Exception {
26  0 AdaptedMap adaptedMap = new AdaptedMap();
27  0 for (Entry<String, String> entry : map.entrySet()) {
28  0 AdaptedEntry adaptedEntry = new AdaptedEntry();
29  0 adaptedEntry.key = transform(entry.getKey());
30  0 adaptedEntry.value = entry.getValue();
31  0 adaptedMap.entries.add(adaptedEntry);
32    }
33  0 return adaptedMap;
34    }
35   
 
36  0 toggle @Override
37    public Map<String, String> unmarshal(AdaptedMap adaptedMap) throws Exception {
38  0 List<AdaptedEntry> adaptedEntries = adaptedMap.entries;
39  0 Map<String, String> map = new HashMap<>(adaptedEntries.size());
40  0 for (AdaptedEntry adaptedEntry : adaptedEntries) {
41  0 map.put(adaptedEntry.key, adaptedEntry.value);
42    }
43  0 return map;
44    }
45   
 
46  1 toggle static String untransform(String key) {
47  1 if (key == null) {
48  0 return "key";
49    } else {
50  1 return key.replaceAll("__", " ");
51    }
52    }
53   
 
54  1 toggle static String transform(String key) {
55  1 if (key != null) {
56  1 return key.replaceAll(" ", "__");
57    } else {
58  0 return "key";
59    }
60    }
61    }