| 1 | package fr.sii.ogham.sms.splitter; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | ||
| 5 | import fr.sii.ogham.sms.exception.message.NoSplitterAbleToSplitMessageException; | |
| 6 | import fr.sii.ogham.sms.exception.message.SplitMessageException; | |
| 7 | ||
| 8 | /** | |
| 9 | * Try to split using any registered {@link MessageSplitter}. | |
| 10 | * | |
| 11 | * <p> | |
| 12 | * For each registered splitter, it checks if the message can be split with it. | |
| 13 | * If it can, then split using the splitter and return the result. If the | |
| 14 | * splitter can't handle the message, try next one. | |
| 15 | * | |
| 16 | * <p> | |
| 17 | * The message can be handled by a registered splitter if it implements | |
| 18 | * {@link SupportingSplitter} and {@link SupportingSplitter#canSplit(String)} | |
| 19 | * returns true. If the registered splitter doesn't implement | |
| 20 | * {@link SupportingSplitter}, the splitter is always considered as able to | |
| 21 | * split the message. | |
| 22 | * | |
| 23 | * | |
| 24 | * @author Aurélien Baudet | |
| 25 | * | |
| 26 | */ | |
| 27 | public class FirstSupportingMessageSplitter implements MessageSplitter { | |
| 28 | private final List<MessageSplitter> delegates; | |
| 29 | ||
| 30 | /** | |
| 31 | * Registers the splitters | |
| 32 | * | |
| 33 | * @param delegates | |
| 34 | * the splitters to try in order | |
| 35 | */ | |
| 36 | public FirstSupportingMessageSplitter(List<MessageSplitter> delegates) { | |
| 37 | super(); | |
| 38 | this.delegates = delegates; | |
| 39 | } | |
| 40 | ||
| 41 | @Override | |
| 42 | public List<Segment> split(String message) throws SplitMessageException { | |
| 43 | for (MessageSplitter splitter : delegates) { | |
| 44 |
4
1. split : negated conditional → NO_COVERAGE 2. split : negated conditional → TIMED_OUT 3. split : negated conditional → KILLED 4. split : negated conditional → KILLED |
if (canSplit(splitter, message)) { |
| 45 |
4
1. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::split → NO_COVERAGE 2. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::split → TIMED_OUT 3. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::split → KILLED 4. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::split → KILLED |
return splitter.split(message); |
| 46 | } | |
| 47 | } | |
| 48 | throw new NoSplitterAbleToSplitMessageException("Failed to split message because no splitter is able to split the message", message); | |
| 49 | } | |
| 50 | ||
| 51 | private static boolean canSplit(MessageSplitter splitter, String message) { | |
| 52 |
4
1. canSplit : negated conditional → NO_COVERAGE 2. canSplit : negated conditional → TIMED_OUT 3. canSplit : negated conditional → KILLED 4. canSplit : negated conditional → KILLED |
if (splitter instanceof SupportingSplitter) { |
| 53 |
8
1. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → NO_COVERAGE 2. canSplit : replaced boolean return with true for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → NO_COVERAGE 3. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → TIMED_OUT 4. canSplit : replaced boolean return with true for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → TIMED_OUT 5. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → KILLED 6. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → KILLED 7. canSplit : replaced boolean return with true for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → KILLED 8. canSplit : replaced boolean return with true for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → KILLED |
return ((SupportingSplitter) splitter).canSplit(message); |
| 54 | } | |
| 55 |
1
1. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → NO_COVERAGE |
return true; |
| 56 | } | |
| 57 | ||
| 58 | } | |
Mutations | ||
| 44 |
1.1 2.2 3.3 4.4 |
|
| 45 |
1.1 2.2 3.3 4.4 |
|
| 52 |
1.1 2.2 3.3 4.4 |
|
| 53 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 55 |
1.1 |