Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.hal.core

File AbstractElement.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart5.png
36% of files have more coverage

Code metrics

20
43
23
1
169
136
36
0.84
1.87
23
1.57

Classes

Class Line # Actions
AbstractElement 14 43 36
0.4534883845.3%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    package io.sunshower.service.hal.core;
2   
3    import io.sunshower.common.Identifier;
4    import io.sunshower.common.rs.MapAdapter;
5    import io.sunshower.common.rs.TypeAttributeClassExtractor;
6    import io.sunshower.service.model.PropertyAwareObject;
7    import java.util.*;
8    import java.util.function.Consumer;
9    import javax.xml.bind.annotation.*;
10    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
11    import org.eclipse.persistence.oxm.annotations.XmlClassExtractor;
12   
13    @XmlClassExtractor(TypeAttributeClassExtractor.class)
 
14    public class AbstractElement<T extends AbstractElement<T>> extends PropertyAwareObject<T>
15    implements Element, Styleable, Iterable<Map.Entry<String, Object>> {
16   
17    /** */
18    @XmlElement private Layout layout;
19   
20    @XmlAttribute private String name;
21   
22    @XmlElement(name = "style")
23    @XmlJavaTypeAdapter(MapAdapter.class)
24    private Stylesheet style;
25   
26    @XmlElement(name = "content")
27    @XmlElementWrapper(name = "contents")
28    private Set<Content> contents;
29   
30    /** */
31    @XmlAttribute(name = "element-type")
32    private ElementType elementType;
33   
34    @XmlElement(name = "element-properties")
35    private Properties elementProperties;
36   
 
37  1 toggle public AbstractElement() {
38  1 super();
39  1 this.name = getId().toString();
40    }
41   
 
42  0 toggle public AbstractElement(String name) {
43  0 this();
44  0 setName(name);
45    }
46   
 
47  0 toggle public String getName() {
48  0 return name;
49    }
50   
 
51  1 toggle public void setName(String name) {
52  1 this.name = name;
53    }
54   
 
55  37 toggle @SuppressWarnings("unchecked")
56    public AbstractElement(Class<T> type) {
57  37 super(type);
58    }
59   
 
60  76 toggle public void setId(Identifier id) {
61  76 super.setId(id);
62    }
63   
 
64  64 toggle @Override
65    public Layout getLayout() {
66  64 if (layout == null) {
67  0 layout = new Layout(this);
68    }
69  64 return layout;
70    }
71   
 
72  38 toggle @Override
73    public void setLayout(Layout layout) {
74  38 this.layout = layout;
75    }
76   
 
77  0 toggle public Stylesheet getStyle() {
78  0 return style;
79    }
80   
 
81  0 toggle public void setStyle(Stylesheet style) {
82  0 this.style = style;
83    }
84   
 
85  0 toggle @Override
86    public Set<Content> getContents() {
87  0 return contents == null ? Collections.emptySet() : contents;
88    }
89   
 
90  1 toggle @Override
91    public void addContent(Content content) {
92  1 if (contents == null) {
93  1 contents = new LinkedHashSet<>();
94    }
95  1 if (content != null) {
96  1 contents.add(content);
97    }
98    }
99   
 
100  1 toggle @Override
101    public void addElementProperty(String key, String value) {
102  1 if (elementProperties == null) {
103  1 elementProperties = new Properties();
104    }
105  1 elementProperties.put(key, value);
106    }
107   
 
108  0 toggle public String getElementProperty(String key) {
109  0 if (elementProperties == null) {
110  0 return null;
111    }
112  0 return elementProperties.getProperty(key);
113    }
114   
 
115  0 toggle public ElementType getElementType() {
116  0 return elementType;
117    }
118   
 
119  0 toggle public void setElementType(ElementType elementType) {
120  0 this.elementType = elementType;
121    }
122   
 
123  38 toggle protected void setDefaults() {
124  38 setLayout(new Layout(this));
125  38 setCreated(new Date());
126  38 setModified(new Date());
127    }
128   
 
129  0 toggle @Override
130    public String getStyle(String key) {
131  0 return checkStyles().get(key);
132    }
133   
 
134  20 toggle @Override
135    public void setStyle(String key, String value) {
136  20 checkStyles().set(key, value);
137    }
138   
 
139  20 toggle private Stylesheet checkStyles() {
140  20 if (style == null) {
141  10 style = new Stylesheet();
142    }
143  20 return style;
144    }
145   
 
146  0 toggle @Override
147    public Iterator<Map.Entry<String, Object>> iterator() {
148  0 if (elementProperties != null && elementProperties.getProperties() != null) {
149  0 return elementProperties.getProperties().entrySet().iterator();
150    }
151  0 return Collections.<String, Object>emptyMap().entrySet().iterator();
152    }
153   
 
154  0 toggle @Override
155    public void forEach(Consumer<? super Map.Entry<String, Object>> action) {
156  0 if (elementProperties != null && elementProperties.getProperties() != null) {
157  0 elementProperties.getProperties().forEach((v, e) -> {});
158    }
159    }
160   
 
161  0 toggle @Override
162    public Spliterator<Map.Entry<String, Object>> spliterator() {
163  0 if (elementProperties != null && elementProperties.getProperties() != null) {
164  0 return Spliterators.spliterator(
165    elementProperties.getProperties().entrySet(), Spliterator.ORDERED | Spliterator.SIZED);
166    }
167  0 return Collections.<String, Object>emptyMap().entrySet().spliterator();
168    }
169    }