| 1 | package fr.sii.ogham.sms.builder.cloudhopper; | |
| 2 | ||
| 3 | import java.util.Random; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.builder.Builder; | |
| 6 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 7 | import fr.sii.ogham.core.fluent.AbstractParent; | |
| 8 | import fr.sii.ogham.sms.splitter.RandomReferenceNumberGenerator; | |
| 9 | import fr.sii.ogham.sms.splitter.ReferenceNumberGenerator; | |
| 10 | ||
| 11 | /** | |
| 12 | * In the cellular phone industry, mobile phones and their networks sometimes | |
| 13 | * support concatenated short message service (or concatenated SMS) to overcome | |
| 14 | * the limitation on the number of characters that can be sent in a single SMS | |
| 15 | * text message transmission (which is usually 160). Using this method, long | |
| 16 | * messages are split into smaller messages by the sending device and recombined | |
| 17 | * at the receiving end. Each message is then billed separately. When the | |
| 18 | * feature works properly, it is nearly transparent to the user, appearing as a | |
| 19 | * single long text message. | |
| 20 | * | |
| 21 | * <p> | |
| 22 | * One way of sending concatenated SMS (CSMS) is to split the message into 153 | |
| 23 | * 7-bit character parts (134 octets), and sending each part with a User Data | |
| 24 | * Header (UDH) tacked onto the beginning. A UDH can be used for various | |
| 25 | * purposes and its contents and size varies accordingly, but a UDH for | |
| 26 | * concatenating SMSes look like this: | |
| 27 | * | |
| 28 | * <ul> | |
| 29 | * <li>Field 1 (1 octet): Length of User Data Header, in this case 05.</li> | |
| 30 | * <li>Field 2 (1 octet): Information Element Identifier, equal to 00 | |
| 31 | * (Concatenated short messages, 8-bit reference number)</li> | |
| 32 | * <li>Field 3 (1 octet): Length of the header, excluding the first two fields; | |
| 33 | * equal to 03</li> | |
| 34 | * <li>Field 4 (1 octet): 00-FF, CSMS reference number, must be same for all the | |
| 35 | * SMS parts in the CSMS</li> | |
| 36 | * <li>Field 5 (1 octet): 00-FF, total number of parts. The value shall remain | |
| 37 | * constant for every short message which makes up the concatenated short | |
| 38 | * message. If the value is zero then the receiving entity shall ignore the | |
| 39 | * whole information element</li> | |
| 40 | * <li>Field 6 (1 octet): 00-FF, this part's number in the sequence. The value | |
| 41 | * shall start at 1 and increment for every short message which makes up the | |
| 42 | * concatenated short message. If the value is zero or greater than the value in | |
| 43 | * Field 5 then the receiving entity shall ignore the whole information element. | |
| 44 | * [ETSI Specification: GSM 03.40 Version 5.3.0: July 1996]</li> | |
| 45 | * </ul> | |
| 46 | * | |
| 47 | * <p> | |
| 48 | * It is possible to use a 16 bit CSMS reference number in order to reduce the | |
| 49 | * probability that two different concatenated messages are sent with identical | |
| 50 | * reference numbers to a receiver. In this case, the User Data Header shall be: | |
| 51 | * | |
| 52 | * <ul> | |
| 53 | * <li>Field 1 (1 octet): Length of User Data Header (UDL), in this case | |
| 54 | * 06.</li> | |
| 55 | * <li>Field 2 (1 octet): Information Element Identifier, equal to 08 | |
| 56 | * (Concatenated short messages, 16-bit reference number)</li> | |
| 57 | * <li>Field 3 (1 octet): Length of the header, excluding the first two fields; | |
| 58 | * equal to 04</li> | |
| 59 | * <li>Field 4 (2 octets): 0000-FFFF, CSMS reference number, must be same for | |
| 60 | * all the SMS parts in the CSMS</li> | |
| 61 | * <li>Field 5 (1 octet): 00-FF, total number of parts. The value shall remain | |
| 62 | * constant for every short message which makes up the concatenated short | |
| 63 | * message. If the value is zero then the receiving entity shall ignore the | |
| 64 | * whole information element</li> | |
| 65 | * <li>Field 6 (1 octet): 00-FF, this part's number in the sequence. The value | |
| 66 | * shall start at 1 and increment for every short message which makes up the | |
| 67 | * concatenated short message. If the value is zero or greater than the value in | |
| 68 | * Field 5 then the receiving entity shall ignore the whole information element. | |
| 69 | * [ETSI Specification: GSM 03.40 Version 5.3.0: July 1996]</li> | |
| 70 | * </ul> | |
| 71 | * | |
| 72 | * | |
| 73 | * Configures reference number generation strategy. | |
| 74 | * | |
| 75 | * | |
| 76 | * @author Aurélien Baudet | |
| 77 | * | |
| 78 | */ | |
| 79 | public class ReferenceNumberGeneratorBuilder extends AbstractParent<MessageSplitterBuilder> implements Builder<ReferenceNumberGenerator> { | |
| 80 | private final BuildContext buildContext; | |
| 81 | private Random random; | |
| 82 | private ReferenceNumberGenerator custom; | |
| 83 | ||
| 84 | /** | |
| 85 | * Initializes the builder with a parent builder. The parent builder is used | |
| 86 | * when calling {@link #and()} method. | |
| 87 | * | |
| 88 | * @param parent | |
| 89 | * the parent builder | |
| 90 | * @param buildContext | |
| 91 | * for registering instances and property evaluation | |
| 92 | */ | |
| 93 | public ReferenceNumberGeneratorBuilder(MessageSplitterBuilder parent, BuildContext buildContext) { | |
| 94 | super(parent); | |
| 95 | this.buildContext = buildContext; | |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Uses a random number for reference number. | |
| 100 | * | |
| 101 | * It uses an instance of {@link Random} to generate random numbers. | |
| 102 | * | |
| 103 | * @return this instance for fluent chaining | |
| 104 | */ | |
| 105 | @SuppressWarnings("squid:S2245") | |
| 106 | public ReferenceNumberGeneratorBuilder random() { | |
| 107 |
5
1. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 2. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 3. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 4. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 5. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED |
return random(new Random()); |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * Uses a random number for reference number. The provided {@link Random} | |
| 112 | * instance is used to generate random numbers. | |
| 113 | * | |
| 114 | * <p> | |
| 115 | * If this method is called several times, only the last {@link Random} | |
| 116 | * instance is used. | |
| 117 | * | |
| 118 | * <p> | |
| 119 | * If random parameter is {@code null} then any previously registered | |
| 120 | * {@link Random} instance won't be used. | |
| 121 | * | |
| 122 | * @param random | |
| 123 | * the {@link Random} instance used to generate random numbers | |
| 124 | * @return this instance for fluent chaining | |
| 125 | */ | |
| 126 | public ReferenceNumberGeneratorBuilder random(Random random) { | |
| 127 | this.random = random; | |
| 128 |
5
1. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 2. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 3. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 4. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED 5. random : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::random → KILLED |
return this; |
| 129 | } | |
| 130 | ||
| 131 | /** | |
| 132 | * Uses a custom reference number generation strategy. This strategy takes | |
| 133 | * precedence over any other generation strategy. | |
| 134 | * | |
| 135 | * <p> | |
| 136 | * If this method is called several times, only the last registered | |
| 137 | * generator is used. | |
| 138 | * | |
| 139 | * <p> | |
| 140 | * If custom parameter is {@code null}, the custom strategy is disabled. | |
| 141 | * Other previously configured strategies (like {@link #random()}) will be | |
| 142 | * used instead. | |
| 143 | * | |
| 144 | * @param custom | |
| 145 | * custom reference number generation strategy | |
| 146 | * @return this instance for fluent chaining | |
| 147 | */ | |
| 148 | public ReferenceNumberGeneratorBuilder generator(ReferenceNumberGenerator custom) { | |
| 149 | this.custom = custom; | |
| 150 |
1
1. generator : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::generator → NO_COVERAGE |
return this; |
| 151 | } | |
| 152 | ||
| 153 | @Override | |
| 154 | public ReferenceNumberGenerator build() { | |
| 155 |
2
1. build : negated conditional → SURVIVED 2. build : negated conditional → KILLED |
if (custom != null) { |
| 156 |
1
1. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::build → NO_COVERAGE |
return custom; |
| 157 | } | |
| 158 |
1
1. build : negated conditional → SURVIVED |
if (random != null) { |
| 159 |
2
1. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::build → SURVIVED 2. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::build → KILLED |
return buildContext.register(new RandomReferenceNumberGenerator(random)); |
| 160 | } | |
| 161 |
1
1. build : replaced return value with null for fr/sii/ogham/sms/builder/cloudhopper/ReferenceNumberGeneratorBuilder::build → NO_COVERAGE |
return buildContext.register(new RandomReferenceNumberGenerator()); |
| 162 | } | |
| 163 | } | |
Mutations | ||
| 107 |
1.1 2.2 3.3 4.4 5.5 |
|
| 128 |
1.1 2.2 3.3 4.4 5.5 |
|
| 150 |
1.1 |
|
| 155 |
1.1 2.2 |
|
| 156 |
1.1 |
|
| 158 |
1.1 |
|
| 159 |
1.1 2.2 |
|
| 161 |
1.1 |