| 1 | package fr.sii.ogham.core.util; | |
| 2 | ||
| 3 | import java.util.function.Predicate; | |
| 4 | ||
| 5 | import fr.sii.ogham.core.message.content.Content; | |
| 6 | ||
| 7 | /** | |
| 8 | * Entry that declares a handler that is capable of handling a particular | |
| 9 | * content if the provided matcher matches the content. | |
| 10 | * | |
| 11 | * The entry has also a priority order. Several handlers may be registered and | |
| 12 | * able to handle a particular content. Only the one with the highest priority | |
| 13 | * is used. | |
| 14 | * | |
| 15 | * @author Aurélien Baudet | |
| 16 | * | |
| 17 | * @param <T> | |
| 18 | * the handler type | |
| 19 | */ | |
| 20 | public class PriorizedMatchingHandler<T> { | |
| 21 | /** | |
| 22 | * The matcher used to check if the content can be handled by the associated | |
| 23 | * handler | |
| 24 | */ | |
| 25 | private final Predicate<Content> contentMatcher; | |
| 26 | /** | |
| 27 | * The handler | |
| 28 | */ | |
| 29 | private final T handler; | |
| 30 | /** | |
| 31 | * The priority of the handler | |
| 32 | */ | |
| 33 | private final int priority; | |
| 34 | ||
| 35 | public PriorizedMatchingHandler(Predicate<Content> contentMatcher, T handler, int priority) { | |
| 36 | super(); | |
| 37 | this.contentMatcher = contentMatcher; | |
| 38 | this.handler = handler; | |
| 39 | this.priority = priority; | |
| 40 | } | |
| 41 | ||
| 42 | public boolean matches(Content content) { | |
| 43 |
8
1. matches : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → NO_COVERAGE 2. matches : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → NO_COVERAGE 3. matches : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → TIMED_OUT 4. matches : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → TIMED_OUT 5. matches : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → KILLED 6. matches : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → KILLED 7. matches : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → KILLED 8. matches : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedMatchingHandler::matches → KILLED |
return contentMatcher.test(content); |
| 44 | } | |
| 45 | ||
| 46 | public T getHandler() { | |
| 47 |
4
1. getHandler : replaced return value with null for fr/sii/ogham/core/util/PriorizedMatchingHandler::getHandler → NO_COVERAGE 2. getHandler : replaced return value with null for fr/sii/ogham/core/util/PriorizedMatchingHandler::getHandler → TIMED_OUT 3. getHandler : replaced return value with null for fr/sii/ogham/core/util/PriorizedMatchingHandler::getHandler → KILLED 4. getHandler : replaced return value with null for fr/sii/ogham/core/util/PriorizedMatchingHandler::getHandler → KILLED |
return handler; |
| 48 | } | |
| 49 | ||
| 50 | public int getPriority() { | |
| 51 |
3
1. getPriority : replaced int return with 0 for fr/sii/ogham/core/util/PriorizedMatchingHandler::getPriority → NO_COVERAGE 2. getPriority : replaced int return with 0 for fr/sii/ogham/core/util/PriorizedMatchingHandler::getPriority → SURVIVED 3. getPriority : replaced int return with 0 for fr/sii/ogham/core/util/PriorizedMatchingHandler::getPriority → TIMED_OUT |
return priority; |
| 52 | } | |
| 53 | } | |
Mutations | ||
| 43 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 47 |
1.1 2.2 3.3 4.4 |
|
| 51 |
1.1 2.2 3.3 |