From d8319925413b9424ec60e52dc2873461a8c93a90 Mon Sep 17 00:00:00 2001 From: Timur Saglam Date: Thu, 3 Oct 2024 19:29:12 +0200 Subject: [PATCH] Adapt TileStack to avoid java.util.Stack in its implementation. --- src/main/java/carcassonne/model/tile/TileStack.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/carcassonne/model/tile/TileStack.java b/src/main/java/carcassonne/model/tile/TileStack.java index e47c83f..34f5274 100644 --- a/src/main/java/carcassonne/model/tile/TileStack.java +++ b/src/main/java/carcassonne/model/tile/TileStack.java @@ -3,17 +3,17 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Queue; import java.util.Random; import java.util.Set; -import java.util.Stack; /** * The stack of tiles for a game. * @author Timur Saglam */ public class TileStack { - private final Stack tiles; + private final List tiles; private final Queue returnedTiles; private final Set returnHistory; private final int multiplier; @@ -36,7 +36,7 @@ public TileStack(TileDistribution distribution, int multiplicator) { */ public TileStack(TileDistribution distribution, int multiplier, Long sortingSeed) { this.multiplier = multiplier; - tiles = new Stack<>(); + tiles = new LinkedList<>(); // LinkedList is better for a stack here returnedTiles = new LinkedList<>(); returnHistory = new HashSet<>(); fillStack(distribution); @@ -50,7 +50,7 @@ public TileStack(TileDistribution distribution, int multiplier, Long sortingSeed } /** - * Draws random tile from the stack and returns it + * Draws random tile from the stack and returns it. * @return the tile or null if the stack is empty. */ public Tile drawTile() { @@ -60,7 +60,8 @@ public Tile drawTile() { if (tiles.isEmpty()) { return returnedTiles.poll(); } - return tiles.pop(); + + return tiles.removeFirst(); } /** @@ -73,7 +74,7 @@ public int getInitialSize() { /** * Getter for the size of the stack. - * @return the amount of tiled on the stack. + * @return the amount of tiles on the stack. */ public int getSize() { return tiles.size() + returnedTiles.size();