| 1 | package fr.sii.ogham.sms.builder; | |
| 2 | ||
| 3 | import fr.sii.ogham.core.builder.Builder; | |
| 4 | import fr.sii.ogham.core.builder.context.BuildContext; | |
| 5 | import fr.sii.ogham.core.builder.context.DefaultBuildContext; | |
| 6 | import fr.sii.ogham.core.builder.env.EnvironmentBuilder; | |
| 7 | import fr.sii.ogham.core.fluent.AbstractParent; | |
| 8 | import fr.sii.ogham.sms.message.PhoneNumber; | |
| 9 | import fr.sii.ogham.sms.message.addressing.AddressedPhoneNumber; | |
| 10 | import fr.sii.ogham.sms.message.addressing.translator.CompositePhoneNumberTranslator; | |
| 11 | import fr.sii.ogham.sms.message.addressing.translator.PhoneNumberHandler; | |
| 12 | import fr.sii.ogham.sms.message.addressing.translator.PhoneNumberTranslator; | |
| 13 | ||
| 14 | /** | |
| 15 | * Configures the recipient phone number conversion (from a {@link PhoneNumber} | |
| 16 | * to an {@link AddressedPhoneNumber}). | |
| 17 | * | |
| 18 | * The {@link PhoneNumber} is used by the developer to provide a simple phone | |
| 19 | * number without knowing how phone number works (no need to handle formats, | |
| 20 | * addressing, countries...). The {@link AddressedPhoneNumber} is used by Ogham | |
| 21 | * implementations to have a phone number that is usable by a technical system. | |
| 22 | * | |
| 23 | * @author Aurélien Baudet | |
| 24 | * | |
| 25 | */ | |
| 26 | public class RecipientNumberBuilder extends AbstractParent<PhoneNumbersBuilder> implements Builder<PhoneNumberTranslator> { | |
| 27 | private final BuildContext buildContext; | |
| 28 | private RecipientNumberFormatBuilder formatBuilder; | |
| 29 | private PhoneNumberTranslator customTranslator; | |
| 30 | ||
| 31 | /** | |
| 32 | * Default constructor used without all Ogham work. | |
| 33 | * | |
| 34 | * <strong>WARNING: use is only if you know what you are doing !</strong> | |
| 35 | */ | |
| 36 | public RecipientNumberBuilder() { | |
| 37 | this(null, new DefaultBuildContext()); | |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * Initializes the builder with a parent builder. The parent builder is used | |
| 42 | * when calling {@link #and()} method. The {@link EnvironmentBuilder} is | |
| 43 | * used to evaluate properties when {@link #build()} method is called. | |
| 44 | * | |
| 45 | * @param parent | |
| 46 | * the parent builder | |
| 47 | * @param buildContext | |
| 48 | * for registering instances and property evaluation | |
| 49 | */ | |
| 50 | public RecipientNumberBuilder(PhoneNumbersBuilder parent, BuildContext buildContext) { | |
| 51 | super(parent); | |
| 52 | this.buildContext = buildContext; | |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Defines which standard conversions may be applied on the phone number to | |
| 57 | * convert it from a {@link PhoneNumber} to an {@link AddressedPhoneNumber}. | |
| 58 | * | |
| 59 | * @return the builder to configure standard phone number conversions | |
| 60 | */ | |
| 61 | public RecipientNumberFormatBuilder format() { | |
| 62 |
8
1. format : negated conditional → NO_COVERAGE 2. format : negated conditional → TIMED_OUT 3. format : negated conditional → KILLED 4. format : negated conditional → KILLED 5. format : negated conditional → KILLED 6. format : negated conditional → KILLED 7. format : negated conditional → KILLED 8. format : negated conditional → KILLED |
if (formatBuilder == null) { |
| 63 | formatBuilder = new RecipientNumberFormatBuilder(this, buildContext); | |
| 64 | } | |
| 65 |
8
1. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → NO_COVERAGE 2. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 3. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 4. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 5. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 6. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 7. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED 8. format : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::format → KILLED |
return formatBuilder; |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Overrides the standard phone number conversions by the provided handler. | |
| 70 | * | |
| 71 | * <p> | |
| 72 | * If you call this method several times, only the last custom handler is | |
| 73 | * used. If you need to apply several conversions, you can use | |
| 74 | * {@link CompositePhoneNumberTranslator} implementation that delegates to | |
| 75 | * {@link PhoneNumberHandler}s. | |
| 76 | * | |
| 77 | * @param handler | |
| 78 | * the handler to use | |
| 79 | * @return this instance for fluent chaining | |
| 80 | */ | |
| 81 | public RecipientNumberBuilder convert(PhoneNumberTranslator handler) { | |
| 82 | this.customTranslator = handler; | |
| 83 |
1
1. convert : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::convert → NO_COVERAGE |
return this; |
| 84 | } | |
| 85 | ||
| 86 | @Override | |
| 87 | public PhoneNumberTranslator build() { | |
| 88 |
6
1. build : negated conditional → SURVIVED 2. build : negated conditional → NO_COVERAGE 3. build : negated conditional → KILLED 4. build : negated conditional → KILLED 5. build : negated conditional → KILLED 6. build : negated conditional → KILLED |
if (customTranslator != null) { |
| 89 |
1
1. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → NO_COVERAGE |
return customTranslator; |
| 90 | } | |
| 91 |
6
1. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → NO_COVERAGE 2. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → SURVIVED 3. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → KILLED 4. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → KILLED 5. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → KILLED 6. build : replaced return value with null for fr/sii/ogham/sms/builder/RecipientNumberBuilder::build → KILLED |
return formatBuilder.build(); |
| 92 | } | |
| 93 | } | |
Mutations | ||
| 62 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 65 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 83 |
1.1 |
|
| 88 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 89 |
1.1 |
|
| 91 |
1.1 2.2 3.3 4.4 5.5 6.6 |