1 | package fr.sii.ogham.core.util; | |
2 | ||
3 | import java.util.Comparator; | |
4 | import java.util.function.ToIntFunction; | |
5 | ||
6 | /** | |
7 | * Comparator used to order objects. Higher priority will come first | |
8 | * | |
9 | * @author Aurélien Baudet | |
10 | * @param <T> | |
11 | * The type of compared object that contains a priority field | |
12 | * | |
13 | */ | |
14 | public class PriorityComparator<T> implements Comparator<T> { | |
15 | private final ToIntFunction<T> priorityAccessor; | |
16 | ||
17 | /** | |
18 | * Initializes with the function used to access the priority attribute of | |
19 | * the compared objects. | |
20 | * | |
21 | * @param priorityAccessor | |
22 | * The function to get the priority value of compared objects | |
23 | */ | |
24 | public PriorityComparator(ToIntFunction<T> priorityAccessor) { | |
25 | super(); | |
26 | this.priorityAccessor = priorityAccessor; | |
27 | } | |
28 | ||
29 | @Override | |
30 | public int compare(T o1, T o2) { | |
31 |
11
1. compare : removed negation → SURVIVED 2. compare : removed negation → NO_COVERAGE 3. compare : replaced int return with 0 for fr/sii/ogham/core/util/PriorityComparator::compare → SURVIVED 4. compare : replaced int return with 0 for fr/sii/ogham/core/util/PriorityComparator::compare → NO_COVERAGE 5. compare : removed negation → TIMED_OUT 6. compare : replaced int return with 0 for fr/sii/ogham/core/util/PriorityComparator::compare → TIMED_OUT 7. compare : removed negation → KILLED 8. compare : removed negation → KILLED 9. compare : removed negation → KILLED 10. compare : replaced int return with 0 for fr/sii/ogham/core/util/PriorityComparator::compare → KILLED 11. compare : replaced int return with 0 for fr/sii/ogham/core/util/PriorityComparator::compare → KILLED |
return -Integer.compare(priorityAccessor.applyAsInt(o1), priorityAccessor.applyAsInt(o2)); |
32 | } | |
33 | ||
34 | } | |
Mutations | ||
31 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 |