1 | package fr.sii.ogham.sms.sender.impl.cloudhopper.preparator; | |
2 | ||
3 | import java.util.ArrayList; | |
4 | import java.util.Arrays; | |
5 | import java.util.List; | |
6 | ||
7 | import com.cloudhopper.commons.gsm.DataCoding; | |
8 | ||
9 | import fr.sii.ogham.sms.encoder.Encoded; | |
10 | import fr.sii.ogham.sms.sender.impl.cloudhopper.exception.DataCodingException; | |
11 | ||
12 | /** | |
13 | * Execute registered {@link DataCodingProvider}s until one returns a non-null | |
14 | * value and returns this value. | |
15 | * | |
16 | * @author Aurélien Baudet | |
17 | * | |
18 | */ | |
19 | public class FirstSupportingDataCodingProvider implements DataCodingProvider { | |
20 | private final List<DataCodingProvider> delegates; | |
21 | ||
22 | /** | |
23 | * Initializes with none, one or several {@link DataCodingProvider}s to | |
24 | * execute. | |
25 | * | |
26 | * @param delegates | |
27 | * the {@link DataCodingProvider}s to execute | |
28 | */ | |
29 | public FirstSupportingDataCodingProvider(DataCodingProvider... delegates) { | |
30 | this(new ArrayList<>(Arrays.asList(delegates))); | |
31 | } | |
32 | ||
33 | /** | |
34 | * Initializes with a list of {@link DataCodingProvider}s to execute. | |
35 | * | |
36 | * @param delegates | |
37 | * the list of {@link DataCodingProvider}s to execute | |
38 | */ | |
39 | public FirstSupportingDataCodingProvider(List<DataCodingProvider> delegates) { | |
40 | super(); | |
41 | this.delegates = delegates; | |
42 | } | |
43 | ||
44 | @Override | |
45 | public DataCoding provide(Encoded encoded) throws DataCodingException { | |
46 | for (DataCodingProvider delegate : delegates) { | |
47 | DataCoding dcs = delegate.provide(encoded); | |
48 |
4
1. provide : negated conditional → NO_COVERAGE 2. provide : negated conditional → TIMED_OUT 3. provide : negated conditional → KILLED 4. provide : negated conditional → KILLED |
if (dcs != null) { |
49 |
4
1. provide : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/preparator/FirstSupportingDataCodingProvider::provide → NO_COVERAGE 2. provide : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/preparator/FirstSupportingDataCodingProvider::provide → TIMED_OUT 3. provide : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/preparator/FirstSupportingDataCodingProvider::provide → KILLED 4. provide : replaced return value with null for fr/sii/ogham/sms/sender/impl/cloudhopper/preparator/FirstSupportingDataCodingProvider::provide → KILLED |
return dcs; |
50 | } | |
51 | } | |
52 | throw new DataCodingException("No DataCodingProvider could determine a valid Data Coding Scheme", encoded); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Register a {@link DataCodingProvider} into the list of possible | |
57 | * providers. | |
58 | * | |
59 | * <p> | |
60 | * The provider is appended to the list. | |
61 | * </p> | |
62 | * | |
63 | * @param provider | |
64 | * the provider to register | |
65 | */ | |
66 | public void register(DataCodingProvider provider) { | |
67 | this.delegates.add(provider); | |
68 | } | |
69 | ||
70 | } | |
Mutations | ||
48 |
1.1 2.2 3.3 4.4 |
|
49 |
1.1 2.2 3.3 4.4 |