1 | package fr.sii.ogham.core.message.content; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import fr.sii.ogham.core.util.ArrayUtils; | |
8 | import fr.sii.ogham.core.util.EqualsBuilder; | |
9 | import fr.sii.ogham.core.util.HashCodeBuilder; | |
10 | ||
11 | /** | |
12 | * Decorator content that provide ability to handle several sub contents. The | |
13 | * aim is to be able to handle messages with several distinct contents like | |
14 | * email for example that can contain at the same time an HTML message and a | |
15 | * text message. The email client implementation is free to display the content | |
16 | * it is able to handle. | |
17 | * | |
18 | * @author Aurélien Baudet | |
19 | * | |
20 | */ | |
21 | public class MultiContent implements Content { | |
22 | /** | |
23 | * The list of sub contents | |
24 | */ | |
25 | private final List<Content> contents; | |
26 | ||
27 | /** | |
28 | * Initialize the content with one or several sub contents directly as strings. | |
29 | * | |
30 | * @param content | |
31 | * the mandatory content | |
32 | * @param contents | |
33 | * the contents either as array or multiple arguments | |
34 | */ | |
35 | public MultiContent(String content, String... contents) { | |
36 | this(toContent(ArrayUtils.concat(content, contents))); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Initialize the content with none, one or several sub contents. | |
41 | * | |
42 | * @param contents | |
43 | * the contents either as array or multiple arguments | |
44 | */ | |
45 | public MultiContent(Content... contents) { | |
46 | this(new ArrayList<>(Arrays.asList(contents))); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Initialize the content with a list of sub contents | |
51 | * | |
52 | * @param contents | |
53 | * the list of sub contents | |
54 | */ | |
55 | public MultiContent(List<Content> contents) { | |
56 | super(); | |
57 | this.contents = contents; | |
58 | } | |
59 | ||
60 | public List<Content> getContents() { | |
61 |
4
1. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → NO_COVERAGE 2. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED 3. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED 4. getContents : replaced return value with Collections.emptyList for fr/sii/ogham/core/message/content/MultiContent::getContents → KILLED |
return contents; |
62 | } | |
63 | ||
64 | /** | |
65 | * Add a sub content to the list of sub contents. | |
66 | * | |
67 | * @param content | |
68 | * the content to add | |
69 | */ | |
70 | public void addContent(Content content) { | |
71 | contents.add(content); | |
72 | } | |
73 | ||
74 | @Override | |
75 | public String toString() { | |
76 | StringBuilder builder = new StringBuilder(); | |
77 | builder.append("MultiContent [contents=").append(contents).append("]"); | |
78 |
1
1. toString : replaced return value with "" for fr/sii/ogham/core/message/content/MultiContent::toString → NO_COVERAGE |
return builder.toString(); |
79 | } | |
80 | | |
81 | @Override | |
82 | public int hashCode() { | |
83 |
2
1. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → NO_COVERAGE 2. hashCode : replaced int return with 0 for fr/sii/ogham/core/message/content/MultiContent::hashCode → KILLED |
return new HashCodeBuilder().append(contents).hashCode(); |
84 | } | |
85 | ||
86 | @Override | |
87 | public boolean equals(Object obj) { | |
88 |
4
1. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE 2. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → NO_COVERAGE 3. equals : replaced boolean return with false for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED 4. equals : replaced boolean return with true for fr/sii/ogham/core/message/content/MultiContent::equals → KILLED |
return new EqualsBuilder(this, obj).appendFields("contents").isEqual(); |
89 | } | |
90 | | |
91 | private static Content[] toContent(String[] strs) { | |
92 | Content[] contents = new Content[strs.length]; | |
93 |
4
1. toContent : changed conditional boundary → NO_COVERAGE 2. toContent : negated conditional → NO_COVERAGE 3. toContent : changed conditional boundary → KILLED 4. toContent : negated conditional → KILLED |
for(int i=0 ; i<strs.length ; i++) { |
94 | contents[i] = new StringContent(strs[i]); | |
95 | } | |
96 |
2
1. toContent : replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → NO_COVERAGE 2. toContent : replaced return value with null for fr/sii/ogham/core/message/content/MultiContent::toContent → KILLED |
return contents; |
97 | } | |
98 | } | |
Mutations | ||
61 |
1.1 2.2 3.3 4.4 |
|
78 |
1.1 |
|
83 |
1.1 2.2 |
|
88 |
1.1 2.2 3.3 4.4 |
|
93 |
1.1 2.2 3.3 4.4 |
|
96 |
1.1 2.2 |