| 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 |
1
1. split : negated conditional → NO_COVERAGE |
if (canSplit(splitter, message)) { |
| 45 |
1
1. split : replaced return value with Collections.emptyList for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::split → NO_COVERAGE |
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 |
1
1. canSplit : negated conditional → NO_COVERAGE |
if (splitter instanceof SupportingSplitter) { |
| 53 |
2
1. canSplit : replaced boolean return with true for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → NO_COVERAGE 2. canSplit : replaced boolean return with false for fr/sii/ogham/sms/splitter/FirstSupportingMessageSplitter::canSplit → NO_COVERAGE |
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 |
|
| 45 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 2.2 |
|
| 55 |
1.1 |