| 1 | package sh.okx.rankup.ranks; | |
| 2 | ||
| 3 | import java.util.ArrayList; | |
| 4 | import java.util.Collection; | |
| 5 | import java.util.Collections; | |
| 6 | import java.util.List; | |
| 7 | import java.util.Objects; | |
| 8 | import lombok.Getter; | |
| 9 | import org.bukkit.entity.Player; | |
| 10 | import sh.okx.rankup.RankupPlugin; | |
| 11 | ||
| 12 | public abstract class RankList<T extends Rank> { | |
| 13 | ||
| 14 | protected RankupPlugin plugin; | |
| 15 |
1
1. getTree : replaced return value with null for sh/okx/rankup/ranks/RankList::getTree → KILLED |
@Getter |
| 16 | private RankTree<T> tree; | |
| 17 | ||
| 18 | public RankList(RankupPlugin plugin, Collection<? extends T> ranks) { | |
| 19 | this.plugin = plugin; | |
| 20 | List<RankElement<T>> rankElements = new ArrayList<>(); | |
| 21 | for (T rank : ranks) { | |
| 22 |
2
1. <init> : negated conditional → KILLED 2. <init> : negated conditional → KILLED |
if (rank != null && validateSection(rank)) { |
| 23 | // find next | |
| 24 | rankElements.add(findNext(rank, rankElements)); | |
| 25 | } else { | |
| 26 | plugin.getLogger().warning("Ignoring rank: " + rank); | |
| 27 | } | |
| 28 | } | |
| 29 | ||
| 30 | for (RankElement<T> rankElement : rankElements) { | |
| 31 |
1
1. <init> : negated conditional → KILLED |
if (rankElement.isRootNode()) { |
| 32 |
1
1. <init> : negated conditional → KILLED |
if (tree == null) { |
| 33 | tree = new RankTree<>(rankElement); | |
| 34 |
1
1. <init> : removed call to sh/okx/rankup/ranks/RankList::addLastRank → KILLED |
addLastRank(plugin); |
| 35 | } else { | |
| 36 | plugin.getLogger().severe("Multiple root rankup nodes detected (a root rankup nodes is a rankup that does not have anything that ranks up to it). This may lead to inconsistent behaviour."); | |
| 37 | plugin.getLogger().severe("Conflicting root node: " + rankElement.getRank() + ". Using root node: " + tree.getFirst().getRank()); | |
| 38 | } | |
| 39 | } | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | protected abstract void addLastRank(RankupPlugin plugin); | |
| 44 | ||
| 45 | private RankElement<T> findNext(T rank, List<RankElement<T>> rankElements) { | |
| 46 | Objects.requireNonNull(rank); | |
| 47 | ||
| 48 | RankElement<T> currentElement = new RankElement<>(rank, null); | |
| 49 | ||
| 50 | for (RankElement<T> rankElement : rankElements) { | |
| 51 | T rank1 = rankElement.getRank(); | |
| 52 |
1
1. findNext : negated conditional → KILLED |
if (rank1.getRank() != null |
| 53 |
1
1. findNext : negated conditional → KILLED |
&& rank1.getRank().equalsIgnoreCase(rank.getNext())) { |
| 54 | // current rank element is the next rank | |
| 55 |
1
1. findNext : removed call to sh/okx/rankup/ranks/RankElement::setNext → NO_COVERAGE |
currentElement.setNext(rankElement); |
| 56 |
1
1. findNext : negated conditional → KILLED |
} else if (rank1.getNext() != null |
| 57 |
1
1. findNext : negated conditional → KILLED |
&& rank1.getNext().equalsIgnoreCase(rank.getRank())) { |
| 58 |
1
1. findNext : removed call to sh/okx/rankup/ranks/RankElement::setNext → KILLED |
rankElement.setNext(currentElement); |
| 59 | } | |
| 60 | } | |
| 61 |
1
1. findNext : replaced return value with null for sh/okx/rankup/ranks/RankList::findNext → KILLED |
return currentElement; |
| 62 | } | |
| 63 | ||
| 64 | protected boolean validateSection(T rank) { | |
| 65 |
1
1. validateSection : negated conditional → SURVIVED |
String name = rank.getRank() == null ? "rank" : rank.getRank(); |
| 66 | String nextField = rank.getNext(); | |
| 67 |
2
1. validateSection : negated conditional → KILLED 2. validateSection : negated conditional → KILLED |
if (nextField == null || nextField.isEmpty()) { |
| 68 | plugin.getLogger().warning("Rankup section " + name + " does not have a 'next' field."); | |
| 69 | plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used."); | |
| 70 | plugin.getLogger().warning("If this is intended as a final rank, you should delete " + name); | |
| 71 |
1
1. validateSection : replaced boolean return with true for sh/okx/rankup/ranks/RankList::validateSection → NO_COVERAGE |
return false; |
| 72 |
1
1. validateSection : negated conditional → KILLED |
} else if (rank.getRequirements() == null) { |
| 73 | plugin.getLogger().warning("Rank " + name + " does not have any requirements."); | |
| 74 |
1
1. validateSection : replaced boolean return with true for sh/okx/rankup/ranks/RankList::validateSection → NO_COVERAGE |
return false; |
| 75 | } | |
| 76 |
1
1. validateSection : replaced boolean return with false for sh/okx/rankup/ranks/RankList::validateSection → KILLED |
return true; |
| 77 | } | |
| 78 | ||
| 79 | public T getFirst() { | |
| 80 |
1
1. getFirst : replaced return value with null for sh/okx/rankup/ranks/RankList::getFirst → KILLED |
return tree.getFirst().getRank(); |
| 81 | } | |
| 82 | ||
| 83 | public T getRankByName(String name) { | |
| 84 |
1
1. getRankByName : negated conditional → KILLED |
if (name == null) { |
| 85 | return null; | |
| 86 | } | |
| 87 | for (T rank : tree) { | |
| 88 |
1
1. getRankByName : negated conditional → KILLED |
if (name.equalsIgnoreCase(rank.getRank())) { |
| 89 |
1
1. getRankByName : replaced return value with null for sh/okx/rankup/ranks/RankList::getRankByName → KILLED |
return rank; |
| 90 | } | |
| 91 | } | |
| 92 | return null; | |
| 93 | } | |
| 94 | ||
| 95 | public RankElement<T> getByName(String name) { | |
| 96 |
1
1. getByName : negated conditional → NO_COVERAGE |
if (name == null) { |
| 97 | return null; | |
| 98 | } | |
| 99 | List<RankElement<T>> rankElements = tree.asList(); | |
| 100 | for (RankElement<T> rank : rankElements) { | |
| 101 |
1
1. getByName : negated conditional → NO_COVERAGE |
if (name.equalsIgnoreCase(rank.getRank().getRank())) { |
| 102 |
1
1. getByName : replaced return value with null for sh/okx/rankup/ranks/RankList::getByName → NO_COVERAGE |
return rank; |
| 103 | } | |
| 104 | } | |
| 105 | return null; | |
| 106 | } | |
| 107 | ||
| 108 | ||
| 109 | public RankElement<T> getByPlayer(Player player) { | |
| 110 | List<RankElement<T>> list = tree.asList(); | |
| 111 |
1
1. getByPlayer : removed call to java/util/Collections::reverse → SURVIVED |
Collections.reverse(list); |
| 112 | for (RankElement<T> t : list) { | |
| 113 |
1
1. getByPlayer : negated conditional → KILLED |
if (t.getRank().isIn(player)) { |
| 114 |
1
1. getByPlayer : replaced return value with null for sh/okx/rankup/ranks/RankList::getByPlayer → KILLED |
return t; |
| 115 | } | |
| 116 | } | |
| 117 | return null; | |
| 118 | } | |
| 119 | ||
| 120 | public T getRankByPlayer(Player player) { | |
| 121 | List<RankElement<T>> list = tree.asList(); | |
| 122 |
1
1. getRankByPlayer : removed call to java/util/Collections::reverse → NO_COVERAGE |
Collections.reverse(list); |
| 123 | for (RankElement<T> t : list) { | |
| 124 |
1
1. getRankByPlayer : negated conditional → NO_COVERAGE |
if (t.getRank().isIn(player)) { |
| 125 |
1
1. getRankByPlayer : replaced return value with null for sh/okx/rankup/ranks/RankList::getRankByPlayer → NO_COVERAGE |
return t.getRank(); |
| 126 | } | |
| 127 | } | |
| 128 | return null; | |
| 129 | } | |
| 130 | } | |
Mutations | ||
| 15 |
1.1 |
|
| 22 |
1.1 2.2 |
|
| 31 |
1.1 |
|
| 32 |
1.1 |
|
| 34 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 55 |
1.1 |
|
| 56 |
1.1 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 61 |
1.1 |
|
| 65 |
1.1 |
|
| 67 |
1.1 2.2 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 74 |
1.1 |
|
| 76 |
1.1 |
|
| 80 |
1.1 |
|
| 84 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 96 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 111 |
1.1 |
|
| 113 |
1.1 |
|
| 114 |
1.1 |
|
| 122 |
1.1 |
|
| 124 |
1.1 |
|
| 125 |
1.1 |