Skip to content

Commit

Permalink
Resolve various Sonar issues to reduce technical debt.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaglam committed Oct 3, 2024
1 parent 7ed2db7 commit 62e8d06
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/carcassonne/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -196,7 +196,7 @@ public String toString() {

private void initializeScores() {
overallScore = 0;
terrainSpecificScores = new HashMap<>();
terrainSpecificScores = new EnumMap<>(TerrainType.class);
for (int i = 0; i < TerrainType.values().length - 1; i++) {
terrainSpecificScores.put(TerrainType.values()[i], 0); // initial scores are zero
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/carcassonne/model/ai/AbstractCarcassonneMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ public AbstractCarcassonneMove(TemporaryTile tile, GridDirection meeplePosition,

@Override
public int compareTo(AbstractCarcassonneMove other) {
return Double.valueOf(getValue()).compareTo(other.getValue());
return Double.compare(getValue(), other.getValue());
}

@Override
public boolean equals(Object other) {
if (other instanceof AbstractCarcassonneMove otherMove) {
return compareTo(otherMove) == 0;
}
return false;
}

@Override
public int hashCode() {
return Double.hashCode(getValue());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/carcassonne/model/grid/GridSpot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static carcassonne.model.grid.GridDirection.CENTER;

import java.util.Collection;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -35,7 +35,7 @@ public GridSpot(Grid grid, int x, int y) {
this.grid = grid;
this.x = x;
this.y = y;
tagMap = new HashMap<>();
tagMap = new EnumMap<>(GridDirection.class);
for (GridDirection direction : GridDirection.values()) {
tagMap.put(direction, new HashSet<>());
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public int getY() {
* @param tilePosition is the specific position.
* @return true if not directly or indirectly tagged.
*/
public Boolean isIndirectlyTagged(GridDirection tilePosition) {
public boolean isIndirectlyTagged(GridDirection tilePosition) {
for (GridDirection otherPosition : GridDirection.values()) {
if (isTagged(otherPosition) && tile.hasConnection(tilePosition, otherPosition)) {
return true;
Expand All @@ -133,7 +133,7 @@ public Boolean isIndirectlyTagged(GridDirection tilePosition) {
* @param tagger is the specific grid pattern.
* @return true if not directly or indirectly tagged by the grid pattern.
*/
public Boolean isIndirectlyTaggedBy(GridDirection tilePosition, GridPattern tagger) {
public boolean isIndirectlyTaggedBy(GridDirection tilePosition, GridPattern tagger) {
for (GridDirection otherPosition : GridDirection.values()) {
if (tile.hasConnection(tilePosition, otherPosition) && tagMap.get(otherPosition).contains(tagger)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carcassonne/view/main/MeepleDepiction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MeepleDepiction {
public MeepleDepiction(int scalingFactor, ControllerFacade controller, GridDirection direction) {
updateMeepleSize(scalingFactor);
terrain = TerrainType.OTHER;
label = new JLabel(PaintShop.getPreviewMeeple(terrain, meepleSize)); // new RigidLabel(meepleSize, meepleSize);
label = new JLabel(PaintShop.getPreviewMeeple(terrain, meepleSize));
label.setHorizontalAlignment(SwingConstants.CENTER);
preview = false;
mouseAdapter = new MouseAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class SecondaryView extends JDialog implements NotifiableView {
* @param controller sets the {@link MainController}.
* @param ui is the main graphical user interface.
*/
public SecondaryView(ControllerFacade controller, MainView ui) {
protected SecondaryView(ControllerFacade controller, MainView ui) {
super(ui);
dialogPanel = new JPanel(new GridBagLayout());
this.controller = controller;
Expand Down

0 comments on commit 62e8d06

Please sign in to comment.