| 1 | package fr.sii.ogham.core.util; | |
| 2 | ||
| 3 | import static java.util.stream.Collectors.toList; | |
| 4 | ||
| 5 | import java.util.ArrayList; | |
| 6 | import java.util.List; | |
| 7 | ||
| 8 | /** | |
| 9 | * Helper class that registers objects with associated priority. Each registered | |
| 10 | * object is then returned as list ordered by priority. The higher priority | |
| 11 | * value comes first in the list. | |
| 12 | * | |
| 13 | * @author Aurélien Baudet | |
| 14 | * | |
| 15 | * @param <P> | |
| 16 | * the type of priorized objects | |
| 17 | */ | |
| 18 | public class PriorizedList<P> { | |
| 19 | private final List<WithPriority<P>> priorities; | |
| 20 | ||
| 21 | /** | |
| 22 | * Initializes with an empty list | |
| 23 | */ | |
| 24 | public PriorizedList() { | |
| 25 | this(new ArrayList<>()); | |
| 26 | } | |
| 27 | ||
| 28 | /** | |
| 29 | * Initializes with some priorized objects | |
| 30 | * | |
| 31 | * @param priorities | |
| 32 | * the priorized objects | |
| 33 | */ | |
| 34 | public PriorizedList(List<WithPriority<P>> priorities) { | |
| 35 | super(); | |
| 36 | this.priorities = priorities; | |
| 37 | } | |
| 38 | ||
| 39 | /** | |
| 40 | * Registers a new priorized object | |
| 41 | * | |
| 42 | * @param priorized | |
| 43 | * the wrapped object with its priority | |
| 44 | * @return this instance for fluent chaining | |
| 45 | */ | |
| 46 | public PriorizedList<P> register(WithPriority<P> priorized) { | |
| 47 | priorities.add(priorized); | |
| 48 |
1
1. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → NO_COVERAGE |
return this; |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Registers an object with its priority | |
| 53 | * | |
| 54 | * @param priorized | |
| 55 | * the object to register | |
| 56 | * @param priority | |
| 57 | * the associated priority | |
| 58 | * @return this instance for fluent chaining | |
| 59 | */ | |
| 60 | public PriorizedList<P> register(P priorized, int priority) { | |
| 61 | priorities.add(new WithPriority<>(priorized, priority)); | |
| 62 |
3
1. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → SURVIVED 2. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → NO_COVERAGE 3. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → TIMED_OUT |
return this; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Merge all priorities of another {@link PriorizedList} into this one. | |
| 67 | * | |
| 68 | * @param other | |
| 69 | * the priority list | |
| 70 | * @return this isntance for fluent chaining | |
| 71 | */ | |
| 72 | public PriorizedList<P> register(PriorizedList<P> other) { | |
| 73 | priorities.addAll(other.getPriorities()); | |
| 74 |
2
1. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → SURVIVED 2. register : replaced return value with null for fr/sii/ogham/core/util/PriorizedList::register → NO_COVERAGE |
return this; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Returns true if this list contains no elements. | |
| 79 | * | |
| 80 | * @return if this list contains no elements | |
| 81 | */ | |
| 82 | public boolean isEmpty() { | |
| 83 |
4
1. isEmpty : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedList::isEmpty → NO_COVERAGE 2. isEmpty : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedList::isEmpty → SURVIVED 3. isEmpty : replaced boolean return with true for fr/sii/ogham/core/util/PriorizedList::isEmpty → NO_COVERAGE 4. isEmpty : replaced boolean return with false for fr/sii/ogham/core/util/PriorizedList::isEmpty → KILLED |
return priorities.isEmpty(); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Get the list of priorities ordered by priority | |
| 88 | * | |
| 89 | * @return ordered list of priorities | |
| 90 | */ | |
| 91 | public List<WithPriority<P>> getPriorities() { | |
| 92 |
2
1. getPriorities : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getPriorities → SURVIVED 2. getPriorities : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getPriorities → NO_COVERAGE |
return sort(); |
| 93 | } | |
| 94 | ||
| 95 | /** | |
| 96 | * Get the list of priorized objects ordered by highest priority. | |
| 97 | * | |
| 98 | * @return list of objects ordered by highet priority | |
| 99 | */ | |
| 100 | public List<P> getOrdered() { | |
| 101 |
8
1. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → NO_COVERAGE 2. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 3. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 4. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 5. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 6. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 7. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED 8. getOrdered : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::getOrdered → KILLED |
return sort().stream().map(WithPriority::getPriorized).collect(toList()); |
| 102 | } | |
| 103 | ||
| 104 | private List<WithPriority<P>> sort() { | |
| 105 |
7
1. sort : removed call to java/util/List::sort → SURVIVED 2. sort : removed call to java/util/List::sort → NO_COVERAGE 3. sort : removed call to java/util/List::sort → KILLED 4. sort : removed call to java/util/List::sort → KILLED 5. sort : removed call to java/util/List::sort → KILLED 6. sort : removed call to java/util/List::sort → KILLED 7. sort : removed call to java/util/List::sort → KILLED |
priorities.sort(WithPriority.comparator()); |
| 106 |
8
1. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → NO_COVERAGE 2. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 3. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 4. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 5. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 6. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 7. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED 8. sort : replaced return value with Collections.emptyList for fr/sii/ogham/core/util/PriorizedList::sort → KILLED |
return priorities; |
| 107 | } | |
| 108 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 62 |
1.1 2.2 3.3 |
|
| 74 |
1.1 2.2 |
|
| 83 |
1.1 2.2 3.3 4.4 |
|
| 92 |
1.1 2.2 |
|
| 101 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 105 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
| 106 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |