| 1 | package fr.sii.ogham.core.template.detector; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.StringJoiner; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.exception.template.EngineDetectionException; | |
| 7 | import fr.sii.ogham.core.resource.path.ResourcePath; | |
| 8 | import fr.sii.ogham.core.template.context.Context; | |
| 9 | ||
| 10 | /** | |
| 11 | * A decorator for template engine detection that relies on other template | |
| 12 | * engine detectors. This decorator implements a logical OR algorithm. It asks | |
| 13 | * each real detector if it can handle the template. If one can handle the | |
| 14 | * template, then it stops immediately and returns true. If none of the real | |
| 15 | * detectors can handle the template, then it returns false. | |
| 16 | * | |
| 17 | * @author Aurélien Baudet | |
| 18 | * | |
| 19 | */ | |
| 20 | public class OrTemplateDetector extends CompositeTemplateDetector { | |
| 21 | ||
| 22 | /** | |
| 23 | * Initialize the composite detector with none, one or several detector | |
| 24 | * implementations. | |
| 25 | * | |
| 26 | * @param detectors | |
| 27 | * the real template engine detector implementations | |
| 28 | */ | |
| 29 | public OrTemplateDetector(List<TemplateEngineDetector> detectors) { | |
| 30 | super(detectors); | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Initialize the composite detector with the provided detector | |
| 35 | * implementation list. | |
| 36 | * | |
| 37 | * @param detectors | |
| 38 | * the real template engine detector implementations | |
| 39 | */ | |
| 40 | public OrTemplateDetector(TemplateEngineDetector... detectors) { | |
| 41 | super(detectors); | |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public boolean canParse(ResourcePath templatePath, Context ctx) throws EngineDetectionException { | |
| 46 | for (TemplateEngineDetector detector : getDetectors()) { | |
| 47 |
5
1. canParse : negated conditional → NO_COVERAGE 2. canParse : negated conditional → SURVIVED 3. canParse : negated conditional → TIMED_OUT 4. canParse : negated conditional → KILLED 5. canParse : negated conditional → KILLED |
if (detector.canParse(templatePath, ctx)) { |
| 48 |
5
1. canParse : replaced boolean return with false for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → NO_COVERAGE 2. canParse : replaced boolean return with false for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED 3. canParse : replaced boolean return with false for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED 4. canParse : replaced boolean return with false for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED 5. canParse : replaced boolean return with false for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED |
return true; |
| 49 | } | |
| 50 | } | |
| 51 |
3
1. canParse : replaced boolean return with true for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → NO_COVERAGE 2. canParse : replaced boolean return with true for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED 3. canParse : replaced boolean return with true for fr/sii/ogham/core/template/detector/OrTemplateDetector::canParse → KILLED |
return false; |
| 52 | } | |
| 53 | ||
| 54 | @Override | |
| 55 | public String toString() { | |
| 56 | StringJoiner joiner = new StringJoiner(" or ", "(", ")"); | |
| 57 | for (TemplateEngineDetector detector : getDetectors()) { | |
| 58 | joiner.add(detector.toString()); | |
| 59 | } | |
| 60 |
3
1. toString : replaced return value with "" for fr/sii/ogham/core/template/detector/OrTemplateDetector::toString → SURVIVED 2. toString : replaced return value with "" for fr/sii/ogham/core/template/detector/OrTemplateDetector::toString → NO_COVERAGE 3. toString : replaced return value with "" for fr/sii/ogham/core/template/detector/OrTemplateDetector::toString → TIMED_OUT |
return joiner.toString(); |
| 61 | } | |
| 62 | } | |
Mutations | ||
| 47 |
1.1 2.2 3.3 4.4 5.5 |
|
| 48 |
1.1 2.2 3.3 4.4 5.5 |
|
| 51 |
1.1 2.2 3.3 |
|
| 60 |
1.1 2.2 3.3 |