| 1 | package com.takenoko.layers.irrigation; | |
| 2 | ||
| 3 | import com.takenoko.engine.Board; | |
| 4 | import com.takenoko.layers.tile.ImprovementType; | |
| 5 | import com.takenoko.vector.PositionVector; | |
| 6 | import java.util.*; | |
| 7 | import java.util.stream.Stream; | |
| 8 | ||
| 9 | public class IrrigationLayer { | |
| 10 | private Map<PositionVector, Boolean> irrigation = new HashMap<>(); | |
| 11 | private Set<EdgePosition> irrigationChannelsPositions = new HashSet<>(); | |
| 12 | private HashSet<EdgePosition> availableEdgePositions = new HashSet<>(); | |
| 13 | ||
| 14 | public IrrigationLayer() { | |
| 15 | irrigation.put(new PositionVector(0, 0, 0), true); | |
| 16 | (new PositionVector(0, 0, 0)) | |
| 17 | .getNeighbors() | |
| 18 |
1
1. <init> : removed call to java/util/List::forEach → KILLED |
.forEach(positionVector -> irrigation.put(positionVector.toPositionVector(), true)); |
| 19 | } | |
| 20 | ||
| 21 | public IrrigationLayer(IrrigationLayer irrigationLayer) { | |
| 22 | irrigation = new HashMap<>(irrigationLayer.irrigation); | |
| 23 | irrigationChannelsPositions = new HashSet<>(irrigationLayer.irrigationChannelsPositions); | |
| 24 | availableEdgePositions = new HashSet<>(irrigationLayer.availableEdgePositions); | |
| 25 | } | |
| 26 | ||
| 27 | public void placeIrrigation(EdgePosition edgePosition, Board board) { | |
| 28 |
1
1. placeIrrigation : negated conditional → KILLED |
if (!availableEdgePositions.contains(edgePosition)) { |
| 29 | throw new IllegalArgumentException("The irrigation channel position is not available"); | |
| 30 | } | |
| 31 | irrigationChannelsPositions.add(edgePosition); | |
| 32 |
1
1. placeIrrigation : negated conditional → KILLED |
if (board.isTile(edgePosition.getLeftTilePosition()) |
| 33 |
1
1. placeIrrigation : negated conditional → KILLED |
&& !board.isIrrigatedAt(edgePosition.getLeftTilePosition())) { |
| 34 | irrigation.put(edgePosition.getLeftTilePosition(), true); | |
| 35 | board.growBamboo(edgePosition.getLeftTilePosition()); | |
| 36 | } | |
| 37 | ||
| 38 |
1
1. placeIrrigation : negated conditional → KILLED |
if (board.isTile(edgePosition.getRightTilePosition()) |
| 39 |
1
1. placeIrrigation : negated conditional → KILLED |
&& !board.isIrrigatedAt(edgePosition.getRightTilePosition())) { |
| 40 | irrigation.put(edgePosition.getRightTilePosition(), true); | |
| 41 | board.growBamboo(edgePosition.getRightTilePosition()); | |
| 42 | } | |
| 43 |
1
1. placeIrrigation : removed call to com/takenoko/layers/irrigation/IrrigationLayer::updateAvailableIrrigationChannelPositions → KILLED |
updateAvailableIrrigationChannelPositions(edgePosition, board); |
| 44 | } | |
| 45 | ||
| 46 | private void updateAvailableIrrigationChannelPositions(EdgePosition edgePosition, Board board) { | |
| 47 | availableEdgePositions.remove(edgePosition); | |
| 48 |
1
1. updateAvailableIrrigationChannelPositions : removed call to com/takenoko/layers/irrigation/IrrigationLayer::updateAvailableIrrigationChannelPositions → KILLED |
updateAvailableIrrigationChannelPositions(edgePosition.getNeighbours().stream(), board); |
| 49 | } | |
| 50 | ||
| 51 | public void updateAvailableIrrigationChannelPositions( | |
| 52 | PositionVector positionOfTilePlaced, Board board) { | |
| 53 | // an irrigation channel can be placed if there is an irrigation channel connected to it or | |
| 54 | // if it is connected to the pond | |
| 55 |
1
1. updateAvailableIrrigationChannelPositions : removed call to com/takenoko/layers/irrigation/IrrigationLayer::updateAvailableIrrigationChannelPositions → KILLED |
updateAvailableIrrigationChannelPositions( |
| 56 | EdgePosition.getEdgePositions(positionOfTilePlaced).stream(), board); | |
| 57 | ||
| 58 | // if the tile has a watershed improvement, it is irrigated | |
| 59 | board.getTileAt(positionOfTilePlaced) | |
| 60 | .getImprovement() | |
| 61 |
1
1. updateAvailableIrrigationChannelPositions : removed call to java/util/Optional::ifPresent → KILLED |
.ifPresent( |
| 62 | improvement -> { | |
| 63 |
1
1. lambda$updateAvailableIrrigationChannelPositions$1 : negated conditional → KILLED |
if (improvement.equals(ImprovementType.WATERSHED)) { |
| 64 | irrigation.put(positionOfTilePlaced, true); | |
| 65 | } | |
| 66 | }); | |
| 67 | ||
| 68 |
1
1. updateAvailableIrrigationChannelPositions : negated conditional → KILLED |
if (board.isIrrigatedAt(positionOfTilePlaced)) { |
| 69 | board.growBamboo(positionOfTilePlaced); | |
| 70 | } | |
| 71 | } | |
| 72 | ||
| 73 | private void updateAvailableIrrigationChannelPositions( | |
| 74 | Stream<EdgePosition> edgePositionStream, Board board) { | |
| 75 | edgePositionStream | |
| 76 |
2
1. lambda$updateAvailableIrrigationChannelPositions$2 : negated conditional → KILLED 2. lambda$updateAvailableIrrigationChannelPositions$2 : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$2 → KILLED |
.filter(edgePosition -> !irrigationChannelsPositions.contains(edgePosition)) |
| 77 | .filter( | |
| 78 | edgePosition -> | |
| 79 |
2
1. lambda$updateAvailableIrrigationChannelPositions$3 : negated conditional → KILLED 2. lambda$updateAvailableIrrigationChannelPositions$3 : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$3 → KILLED |
board.isTile(edgePosition.getLeftTilePosition()) |
| 80 |
1
1. lambda$updateAvailableIrrigationChannelPositions$3 : negated conditional → KILLED |
&& board.isTile(edgePosition.getRightTilePosition())) |
| 81 | .filter( | |
| 82 | edgePosition -> | |
| 83 |
2
1. lambda$updateAvailableIrrigationChannelPositions$5 : replaced boolean return with false for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$5 → KILLED 2. lambda$updateAvailableIrrigationChannelPositions$5 : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$5 → KILLED |
edgePosition.getNeighbours().stream() |
| 84 | .anyMatch( | |
| 85 | o -> | |
| 86 |
2
1. lambda$updateAvailableIrrigationChannelPositions$4 : negated conditional → KILLED 2. lambda$updateAvailableIrrigationChannelPositions$4 : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$4 → KILLED |
irrigationChannelsPositions.contains(o) |
| 87 | || EdgePosition.getEdgePositions( | |
| 88 | new PositionVector( | |
| 89 | 0, 0, 0)) | |
| 90 |
1
1. lambda$updateAvailableIrrigationChannelPositions$4 : negated conditional → KILLED |
.contains(o))) |
| 91 | .filter( | |
| 92 | edgePosition -> | |
| 93 |
1
1. lambda$updateAvailableIrrigationChannelPositions$6 : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::lambda$updateAvailableIrrigationChannelPositions$6 → KILLED |
!EdgePosition.getEdgePositions(new PositionVector(0, 0, 0)) |
| 94 |
1
1. lambda$updateAvailableIrrigationChannelPositions$6 : negated conditional → KILLED |
.contains(edgePosition)) |
| 95 |
1
1. updateAvailableIrrigationChannelPositions : removed call to java/util/stream/Stream::forEach → KILLED |
.forEach(availableEdgePositions::add); |
| 96 | } | |
| 97 | ||
| 98 | public IrrigationLayer copy() { | |
| 99 |
1
1. copy : replaced return value with null for com/takenoko/layers/irrigation/IrrigationLayer::copy → KILLED |
return new IrrigationLayer(this); |
| 100 | } | |
| 101 | ||
| 102 | public Set<EdgePosition> getAvailableEdgePositions() { | |
| 103 |
1
1. getAvailableEdgePositions : replaced return value with Collections.emptySet for com/takenoko/layers/irrigation/IrrigationLayer::getAvailableEdgePositions → KILLED |
return new HashSet<>(availableEdgePositions); |
| 104 | } | |
| 105 | ||
| 106 | public Set<EdgePosition> getIrrigationChannelsPositions() { | |
| 107 |
1
1. getIrrigationChannelsPositions : replaced return value with Collections.emptySet for com/takenoko/layers/irrigation/IrrigationLayer::getIrrigationChannelsPositions → TIMED_OUT |
return new HashSet<>(irrigationChannelsPositions); |
| 108 | } | |
| 109 | ||
| 110 | public boolean isIrrigatedAt(PositionVector positionVector) { | |
| 111 | irrigation.putIfAbsent(positionVector, false); | |
| 112 |
2
1. isIrrigatedAt : replaced boolean return with false for com/takenoko/layers/irrigation/IrrigationLayer::isIrrigatedAt → KILLED 2. isIrrigatedAt : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::isIrrigatedAt → KILLED |
return irrigation.get(positionVector); |
| 113 | } | |
| 114 | ||
| 115 | @Override | |
| 116 | public boolean equals(Object o) { | |
| 117 |
2
1. equals : replaced boolean return with false for com/takenoko/layers/irrigation/IrrigationLayer::equals → NO_COVERAGE 2. equals : negated conditional → TIMED_OUT |
if (this == o) return true; |
| 118 |
3
1. equals : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::equals → NO_COVERAGE 2. equals : negated conditional → KILLED 3. equals : negated conditional → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
| 119 | IrrigationLayer that = (IrrigationLayer) o; | |
| 120 |
2
1. equals : replaced boolean return with true for com/takenoko/layers/irrigation/IrrigationLayer::equals → TIMED_OUT 2. equals : negated conditional → KILLED |
return Objects.equals(irrigation, that.irrigation) |
| 121 |
1
1. equals : negated conditional → KILLED |
&& Objects.equals( |
| 122 | getIrrigationChannelsPositions(), that.getIrrigationChannelsPositions()) | |
| 123 |
1
1. equals : negated conditional → KILLED |
&& Objects.equals(getAvailableEdgePositions(), that.getAvailableEdgePositions()); |
| 124 | } | |
| 125 | ||
| 126 | @Override | |
| 127 | public int hashCode() { | |
| 128 |
1
1. hashCode : replaced int return with 0 for com/takenoko/layers/irrigation/IrrigationLayer::hashCode → TIMED_OUT |
return Objects.hash( |
| 129 | irrigation, getIrrigationChannelsPositions(), getAvailableEdgePositions()); | |
| 130 | } | |
| 131 | } | |
Mutations | ||
| 18 |
1.1 |
|
| 28 |
1.1 |
|
| 32 |
1.1 |
|
| 33 |
1.1 |
|
| 38 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 48 |
1.1 |
|
| 55 |
1.1 |
|
| 61 |
1.1 |
|
| 63 |
1.1 |
|
| 68 |
1.1 |
|
| 76 |
1.1 2.2 |
|
| 79 |
1.1 2.2 |
|
| 80 |
1.1 |
|
| 83 |
1.1 2.2 |
|
| 86 |
1.1 2.2 |
|
| 90 |
1.1 |
|
| 93 |
1.1 |
|
| 94 |
1.1 |
|
| 95 |
1.1 |
|
| 99 |
1.1 |
|
| 103 |
1.1 |
|
| 107 |
1.1 |
|
| 112 |
1.1 2.2 |
|
| 117 |
1.1 2.2 |
|
| 118 |
1.1 2.2 3.3 |
|
| 120 |
1.1 2.2 |
|
| 121 |
1.1 |
|
| 123 |
1.1 |
|
| 128 |
1.1 |