| 1 | package com.takenoko.inventory; | |
| 2 | ||
| 3 | import com.takenoko.layers.tile.ImprovementType; | |
| 4 | import com.takenoko.layers.tile.TileColor; | |
| 5 | import java.util.EnumMap; | |
| 6 | import java.util.Map; | |
| 7 | import java.util.Objects; | |
| 8 | ||
| 9 | /** Inventory contains elements stored by player */ | |
| 10 | public class Inventory { | |
| 11 | private final Map<TileColor, InventoryBambooStack> bambooStacks; | |
| 12 | private final InventoryImprovements inventoryImprovements; | |
| 13 | ||
| 14 | private int irrigationChannelsCount = 0; | |
| 15 | ||
| 16 | /** | |
| 17 | * Constructor | |
| 18 | * | |
| 19 | * @param bambooStacks bamboo stacks | |
| 20 | * @param inventoryImprovements improvements | |
| 21 | */ | |
| 22 | public Inventory( | |
| 23 | Map<TileColor, InventoryBambooStack> bambooStacks, | |
| 24 | InventoryImprovements inventoryImprovements) { | |
| 25 | this.bambooStacks = bambooStacks; | |
| 26 | this.inventoryImprovements = inventoryImprovements; | |
| 27 | } | |
| 28 | ||
| 29 | /** | |
| 30 | * Constructor | |
| 31 | * | |
| 32 | * @param bambooStacks bamboo stacks | |
| 33 | */ | |
| 34 | public Inventory(Map<TileColor, InventoryBambooStack> bambooStacks) { | |
| 35 | this(bambooStacks, new InventoryImprovements()); | |
| 36 | } | |
| 37 | ||
| 38 | /** Constructor */ | |
| 39 | public Inventory() { | |
| 40 | this(new EnumMap<>(TileColor.class), new InventoryImprovements()); | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Constructor | |
| 45 | * | |
| 46 | * @param inventory inventory | |
| 47 | */ | |
| 48 | public Inventory(Inventory inventory) { | |
| 49 | this.bambooStacks = new EnumMap<>(TileColor.class); | |
| 50 | ||
| 51 | this.bambooStacks.put(TileColor.GREEN, inventory.getBambooStack(TileColor.GREEN).copy()); | |
| 52 | this.bambooStacks.put(TileColor.YELLOW, inventory.getBambooStack(TileColor.YELLOW).copy()); | |
| 53 | this.bambooStacks.put(TileColor.PINK, inventory.getBambooStack(TileColor.PINK).copy()); | |
| 54 | ||
| 55 | this.inventoryImprovements = inventory.getInventoryImprovements().copy(); | |
| 56 | this.irrigationChannelsCount = inventory.getIrrigationChannelsCount(); | |
| 57 | } | |
| 58 | ||
| 59 | /** add 1 bamboo to the inventory */ | |
| 60 | public void collectBamboo(TileColor tileColor) { | |
| 61 |
1
1. collectBamboo : removed call to com/takenoko/inventory/InventoryBambooStack::collectBamboo → TIMED_OUT |
getBambooStack(tileColor).collectBamboo(); |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * @param improvementType store an improvement in order to use it later on | |
| 66 | */ | |
| 67 | public void storeImprovement(ImprovementType improvementType) { | |
| 68 |
1
1. storeImprovement : removed call to com/takenoko/inventory/InventoryImprovements::store → KILLED |
getInventoryImprovements().store(improvementType); |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * @param improvementType use improvement previously stored | |
| 73 | */ | |
| 74 | public void useImprovement(ImprovementType improvementType) { | |
| 75 |
1
1. useImprovement : removed call to com/takenoko/inventory/InventoryImprovements::use → KILLED |
getInventoryImprovements().use(improvementType); |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * @return number of bamboos in Inventory | |
| 80 | */ | |
| 81 | public int getBambooCount() { | |
| 82 |
1
1. getBambooCount : replaced int return with 0 for com/takenoko/inventory/Inventory::getBambooCount → NO_COVERAGE |
return getBambooCount(TileColor.GREEN) |
| 83 |
1
1. getBambooCount : Replaced integer addition with subtraction → NO_COVERAGE |
+ getBambooCount(TileColor.YELLOW) |
| 84 |
1
1. getBambooCount : Replaced integer addition with subtraction → NO_COVERAGE |
+ getBambooCount(TileColor.PINK); |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Return the number of bamboo of a specific color | |
| 89 | * | |
| 90 | * @param tileColor color of bamboo | |
| 91 | * @return number of bamboos in Inventory | |
| 92 | */ | |
| 93 | public int getBambooCount(TileColor tileColor) { | |
| 94 |
1
1. getBambooCount : replaced int return with 0 for com/takenoko/inventory/Inventory::getBambooCount → TIMED_OUT |
return getBambooStack(tileColor).getBambooCount(); |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * @return the bambooStack | |
| 99 | */ | |
| 100 | public InventoryBambooStack getBambooStack(TileColor tileColor) { | |
| 101 |
1
1. lambda$getBambooStack$0 : replaced return value with null for com/takenoko/inventory/Inventory::lambda$getBambooStack$0 → KILLED |
bambooStacks.computeIfAbsent(tileColor, k -> new InventoryBambooStack(0)); |
| 102 |
1
1. getBambooStack : replaced return value with null for com/takenoko/inventory/Inventory::getBambooStack → KILLED |
return bambooStacks.get(tileColor); |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * @return the list of stored improvements | |
| 107 | */ | |
| 108 | public InventoryImprovements getInventoryImprovements() { | |
| 109 |
1
1. getInventoryImprovements : replaced return value with null for com/takenoko/inventory/Inventory::getInventoryImprovements → KILLED |
return inventoryImprovements; |
| 110 | } | |
| 111 | ||
| 112 | public void collectIrrigationChannel() { | |
| 113 |
1
1. collectIrrigationChannel : Replaced integer addition with subtraction → TIMED_OUT |
irrigationChannelsCount++; |
| 114 | } | |
| 115 | ||
| 116 | public int getIrrigationChannelsCount() { | |
| 117 |
1
1. getIrrigationChannelsCount : replaced int return with 0 for com/takenoko/inventory/Inventory::getIrrigationChannelsCount → TIMED_OUT |
return irrigationChannelsCount; |
| 118 | } | |
| 119 | ||
| 120 | public void useIrrigationChannel() { | |
| 121 |
1
1. useIrrigationChannel : Replaced integer subtraction with addition → TIMED_OUT |
irrigationChannelsCount--; |
| 122 | } | |
| 123 | ||
| 124 | /** reset inventory */ | |
| 125 | public void clear() { | |
| 126 |
1
1. clear : removed call to java/util/Map::clear → TIMED_OUT |
bambooStacks.clear(); |
| 127 |
1
1. clear : removed call to com/takenoko/inventory/InventoryImprovements::clear → KILLED |
inventoryImprovements.clear(); |
| 128 | irrigationChannelsCount = 0; | |
| 129 | } | |
| 130 | ||
| 131 | public Inventory copy() { | |
| 132 |
1
1. copy : replaced return value with null for com/takenoko/inventory/Inventory::copy → KILLED |
return new Inventory(this); |
| 133 | } | |
| 134 | ||
| 135 | @Override | |
| 136 | public boolean equals(Object o) { | |
| 137 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/inventory/Inventory::equals → KILLED |
if (this == o) return true; |
| 138 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/inventory/Inventory::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
| 139 | Inventory inventory = (Inventory) o; | |
| 140 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with true for com/takenoko/inventory/Inventory::equals → KILLED |
return Objects.equals(bambooStacks, inventory.bambooStacks) |
| 141 |
1
1. equals : negated conditional → KILLED |
&& inventoryImprovements.equals(inventory.inventoryImprovements); |
| 142 | } | |
| 143 | ||
| 144 | @Override | |
| 145 | public int hashCode() { | |
| 146 |
1
1. hashCode : replaced int return with 0 for com/takenoko/inventory/Inventory::hashCode → KILLED |
return Objects.hash(bambooStacks, inventoryImprovements); |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Method to verify whether the inventory contains the improvement type specified or not | |
| 151 | * | |
| 152 | * @param improvementType improvement type | |
| 153 | */ | |
| 154 | public boolean hasImprovement(ImprovementType improvementType) { | |
| 155 |
2
1. hasImprovement : replaced boolean return with false for com/takenoko/inventory/Inventory::hasImprovement → KILLED 2. hasImprovement : replaced boolean return with true for com/takenoko/inventory/Inventory::hasImprovement → KILLED |
return inventoryImprovements.hasImprovement(improvementType); |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * Method to verify whether the inventory contains any improvement or not | |
| 160 | * | |
| 161 | * @return true if the inventory contains any improvement, false otherwise | |
| 162 | */ | |
| 163 | public boolean hasImprovement() { | |
| 164 |
2
1. hasImprovement : negated conditional → TIMED_OUT 2. hasImprovement : replaced boolean return with true for com/takenoko/inventory/Inventory::hasImprovement → KILLED |
return !inventoryImprovements.isEmpty(); |
| 165 | } | |
| 166 | ||
| 167 | /** | |
| 168 | * Remove bamboo from the player's inventory when an objective is redeemed | |
| 169 | * | |
| 170 | * @param bambooTarget how many bamboo to use | |
| 171 | */ | |
| 172 | public void useBamboo(Map<TileColor, Integer> bambooTarget) { | |
| 173 |
2
1. lambda$useBamboo$1 : removed call to com/takenoko/inventory/InventoryBambooStack::useBamboo → TIMED_OUT 2. useBamboo : removed call to java/util/Map::forEach → TIMED_OUT |
bambooTarget.forEach((tileColor, count) -> getBambooStack(tileColor).useBamboo(count)); |
| 174 | } | |
| 175 | ||
| 176 | @Override | |
| 177 | public String toString() { | |
| 178 |
1
1. toString : replaced return value with "" for com/takenoko/inventory/Inventory::toString → TIMED_OUT |
return "Inventory{" |
| 179 | + "bambooStacks=" | |
| 180 | + bambooStacks | |
| 181 | + ", inventoryImprovements=" | |
| 182 | + inventoryImprovements | |
| 183 | + '}'; | |
| 184 | } | |
| 185 | ||
| 186 | public int getImprovementCount(ImprovementType improvementType) { | |
| 187 |
1
1. getImprovementCount : replaced int return with 0 for com/takenoko/inventory/Inventory::getImprovementCount → TIMED_OUT |
return inventoryImprovements.getImprovementCount(improvementType); |
| 188 | } | |
| 189 | } | |
Mutations | ||
| 61 |
1.1 |
|
| 68 |
1.1 |
|
| 75 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 94 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 117 |
1.1 |
|
| 121 |
1.1 |
|
| 126 |
1.1 |
|
| 127 |
1.1 |
|
| 132 |
1.1 |
|
| 137 |
1.1 2.2 |
|
| 138 |
1.1 2.2 3.3 |
|
| 140 |
1.1 2.2 |
|
| 141 |
1.1 |
|
| 146 |
1.1 |
|
| 155 |
1.1 2.2 |
|
| 164 |
1.1 2.2 |
|
| 173 |
1.1 2.2 |
|
| 178 |
1.1 |
|
| 187 |
1.1 |