1 | package fr.sii.ogham.core.translator.content; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import org.slf4j.Logger; | |
8 | import org.slf4j.LoggerFactory; | |
9 | ||
10 | import fr.sii.ogham.core.exception.handler.ContentTranslatorException; | |
11 | import fr.sii.ogham.core.message.content.Content; | |
12 | ||
13 | /** | |
14 | * Decorator that loop through all delegate translators to transform the content | |
15 | * of the message. Every translator will be called to update the content. Each | |
16 | * translator receive the content that may be updated by the previous | |
17 | * translator. | |
18 | * | |
19 | * @author Aurélien Baudet | |
20 | * | |
21 | */ | |
22 | public class EveryContentTranslator implements ContentTranslator { | |
23 | private static final Logger LOG = LoggerFactory.getLogger(EveryContentTranslator.class); | |
24 | ||
25 | /** | |
26 | * The list of translators used to update the message content | |
27 | */ | |
28 | private List<ContentTranslator> translators; | |
29 | ||
30 | /** | |
31 | * Initialize the decorator with none, one or several translator | |
32 | * implementations. The registration order may be important. | |
33 | * | |
34 | * @param translators | |
35 | * the translators to register | |
36 | */ | |
37 | public EveryContentTranslator(ContentTranslator... translators) { | |
38 | this(new ArrayList<>(Arrays.asList(translators))); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Initialize the decorator with the provided translator implementations. | |
43 | * The registration order may be important. | |
44 | * | |
45 | * @param translators | |
46 | * the translators to register | |
47 | */ | |
48 | public EveryContentTranslator(List<ContentTranslator> translators) { | |
49 | super(); | |
50 | this.translators = translators; | |
51 | } | |
52 | ||
53 | @Override | |
54 | public Content translate(Content content) throws ContentTranslatorException { | |
55 | Content result = content; | |
56 | for (ContentTranslator translator : translators) { | |
57 | LOG.debug("Applying translator {} on content", translator); | |
58 | LOG.trace("content: {}", content); | |
59 | result = translator.translate(result); | |
60 | } | |
61 |
5
1. translate : replaced return value with null for fr/sii/ogham/core/translator/content/EveryContentTranslator::translate → SURVIVED 2. translate : replaced return value with null for fr/sii/ogham/core/translator/content/EveryContentTranslator::translate → NO_COVERAGE 3. translate : replaced return value with null for fr/sii/ogham/core/translator/content/EveryContentTranslator::translate → TIMED_OUT 4. translate : replaced return value with null for fr/sii/ogham/core/translator/content/EveryContentTranslator::translate → KILLED 5. translate : replaced return value with null for fr/sii/ogham/core/translator/content/EveryContentTranslator::translate → KILLED |
return result; |
62 | } | |
63 | ||
64 | /** | |
65 | * Register a new translator. The translator is added at the end. | |
66 | * | |
67 | * @param translator | |
68 | * the translator to register | |
69 | */ | |
70 | public void addTranslator(ContentTranslator translator) { | |
71 | translators.add(translator); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Get the registered translators. | |
76 | * | |
77 | * @return the list of translators | |
78 | */ | |
79 | public List<ContentTranslator> getTranslators() { | |
80 |
3
1. getTranslators : replaced return value with Collections.emptyList for fr/sii/ogham/core/translator/content/EveryContentTranslator::getTranslators → NO_COVERAGE 2. getTranslators : replaced return value with Collections.emptyList for fr/sii/ogham/core/translator/content/EveryContentTranslator::getTranslators → SURVIVED 3. getTranslators : replaced return value with Collections.emptyList for fr/sii/ogham/core/translator/content/EveryContentTranslator::getTranslators → TIMED_OUT |
return translators; |
81 | } | |
82 | ||
83 | @Override | |
84 | public String toString() { | |
85 | StringBuilder builder = new StringBuilder(); | |
86 | builder.append("EveryContentTranslator [translators=").append(translators).append("]"); | |
87 |
3
1. toString : replaced return value with "" for fr/sii/ogham/core/translator/content/EveryContentTranslator::toString → NO_COVERAGE 2. toString : replaced return value with "" for fr/sii/ogham/core/translator/content/EveryContentTranslator::toString → SURVIVED 3. toString : replaced return value with "" for fr/sii/ogham/core/translator/content/EveryContentTranslator::toString → TIMED_OUT |
return builder.toString(); |
88 | } | |
89 | } | |
Mutations | ||
61 |
1.1 2.2 3.3 4.4 5.5 |
|
80 |
1.1 2.2 3.3 |
|
87 |
1.1 2.2 3.3 |