1 | package com.takenoko.layers.tile; | |
2 | ||
3 | import java.util.Objects; | |
4 | import java.util.Optional; | |
5 | ||
6 | /** Class Tile represents a tile in the game. A tile has a type {@link TileType}. */ | |
7 | public class Tile { | |
8 | private final TileType type; | |
9 | private final TileColor color; | |
10 | private ImprovementType improvement; | |
11 | ||
12 | /** | |
13 | * Constructor of the class Tile. It creates a tile with the default type OTHER {@link | |
14 | * TileType}. | |
15 | */ | |
16 | public Tile() { | |
17 | this(TileType.OTHER); | |
18 | } | |
19 | ||
20 | public Tile(TileColor color) { | |
21 | this(TileType.OTHER, null, color); | |
22 | } | |
23 | ||
24 | /** | |
25 | * Constructor of the class Tile. It creates a tile with the given type. | |
26 | * | |
27 | * @param type the type of the tile | |
28 | */ | |
29 | public Tile(TileType type) { | |
30 | this(type, null, TileColor.PINK); | |
31 | } | |
32 | ||
33 | /** | |
34 | * Constructor of the class Tile. It creates a tile with the given type and improvement. | |
35 | * | |
36 | * @param type the type of the tile | |
37 | * @param color the color of the tile | |
38 | */ | |
39 | public Tile(TileType type, ImprovementType improvement, TileColor color) { | |
40 | this.type = type; | |
41 | this.improvement = improvement; | |
42 | this.color = color; | |
43 | } | |
44 | ||
45 | /** | |
46 | * Copy Constructor | |
47 | * | |
48 | * @param tile the tile to copy | |
49 | */ | |
50 | public Tile(Tile tile) { | |
51 | this.type = tile.type; | |
52 | this.improvement = tile.improvement; | |
53 | this.color = tile.color; | |
54 | } | |
55 | ||
56 | public Tile(ImprovementType improvementType) { | |
57 | this(TileType.OTHER, improvementType, TileColor.PINK); | |
58 | } | |
59 | ||
60 | public Tile(ImprovementType improvementType, TileColor tileColor) { | |
61 | this(TileType.OTHER, improvementType, tileColor); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Get the type of the tile. | |
66 | * | |
67 | * @return the type of the tile | |
68 | */ | |
69 | public TileType getType() { | |
70 |
1
1. getType : replaced return value with null for com/takenoko/layers/tile/Tile::getType → KILLED |
return type; |
71 | } | |
72 | ||
73 | /** | |
74 | * Get the improvement of the tile. | |
75 | * | |
76 | * @return the improvement of the tile | |
77 | */ | |
78 | public Optional<ImprovementType> getImprovement() { | |
79 |
1
1. getImprovement : replaced return value with Optional.empty for com/takenoko/layers/tile/Tile::getImprovement → KILLED |
return Optional.ofNullable(improvement); |
80 | } | |
81 | ||
82 | /** Set the improvement of the tile. If the improvement is null, throw an exception. */ | |
83 | public void setImprovement(ImprovementType improvement) { | |
84 |
1
1. setImprovement : negated conditional → KILLED |
if (this.improvement != null) { |
85 | throw new IllegalStateException("The tile already has an improvement"); | |
86 | } | |
87 | this.improvement = improvement; | |
88 | } | |
89 | ||
90 | public TileColor getColor() { | |
91 |
1
1. getColor : replaced return value with null for com/takenoko/layers/tile/Tile::getColor → KILLED |
return color; |
92 | } | |
93 | ||
94 | @Override | |
95 | public boolean equals(Object o) { | |
96 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/layers/tile/Tile::equals → KILLED |
if (this == o) return true; |
97 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/layers/tile/Tile::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
98 | Tile tile = (Tile) o; | |
99 | ||
100 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with true for com/takenoko/layers/tile/Tile::equals → KILLED |
return type == tile.type |
101 |
2
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED |
&& Objects.equals(improvement, tile.improvement) |
102 | && color == tile.color; | |
103 | } | |
104 | ||
105 | @Override | |
106 | public int hashCode() { | |
107 |
1
1. hashCode : replaced int return with 0 for com/takenoko/layers/tile/Tile::hashCode → KILLED |
return Objects.hash(getType(), getImprovement(), getColor()); |
108 | } | |
109 | ||
110 | public Tile copy() { | |
111 |
1
1. copy : replaced return value with null for com/takenoko/layers/tile/Tile::copy → KILLED |
return new Tile(this); |
112 | } | |
113 | ||
114 | @Override | |
115 | public String toString() { | |
116 |
1
1. toString : replaced return value with "" for com/takenoko/layers/tile/Tile::toString → KILLED |
return "Tile{" + "type=" + type + ", color=" + color + ", improvement=" + improvement + '}'; |
117 | } | |
118 | } | |
Mutations | ||
70 |
1.1 |
|
79 |
1.1 |
|
84 |
1.1 |
|
91 |
1.1 |
|
96 |
1.1 2.2 |
|
97 |
1.1 2.2 3.3 |
|
100 |
1.1 2.2 |
|
101 |
1.1 2.2 |
|
107 |
1.1 |
|
111 |
1.1 |
|
116 |
1.1 |