From 02293f1826c7ffe20ad39e3c26fe9dd5a304295d Mon Sep 17 00:00:00 2001 From: GabrieleRadice <265572328+GabrieleRadice@users.noreply.github.com> Date: Thu, 2 Apr 2026 19:48:20 +0200 Subject: [PATCH] Add: PlayerTest.java Added Javadoc For "UserName" And "getUserName" --- .../it/polimi/ingsw/gc14/Model/Player.java | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Player.java b/src/main/java/it/polimi/ingsw/gc14/Model/Player.java index 5f67367..428317f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Player.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Player.java @@ -7,11 +7,27 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*; import java.util.ArrayList; import java.util.Arrays; -import static java.lang.Math.abs; - +/** + * Default Player class; contains all identifiers and methods needed. + */ public class Player { - // Getters + /** + * The maximum length allowed for the username string. + */ + private static final int MAX_VALUE = 32; + + // region Getters + /** + * Unique string identifier for players; must not be {@code null} and must not + * exceed {@link #MAX_VALUE} otherwise an {@link IllegalArgumentException} will be thrown + * when the {@link #Player(String) constructor} is called. + */ private String UserName; + + /** + * Getter for the private attribute {@link #UserName}. + * @return String + */ public String getUserName() { return UserName; } @@ -57,9 +73,9 @@ public class Player { * return Game; * } */ - // End getters + // endregion getters - // Setters + // region Setters public void addFood(int Value){ this.FoodValue += Value; } @@ -81,12 +97,12 @@ public class Player { this.PrestigeValue -= Value; } - // End setters + // endregion setters - // Constructors + // region Constructors public Player(String UserName) throws IllegalArgumentException { - if(UserName.isEmpty() || UserName.length() > 32) { - throw new IllegalArgumentException(); + if(UserName.isEmpty() || UserName.length() > MAX_VALUE) { + throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length."); } this.UserName = UserName; @@ -101,8 +117,8 @@ public class Player { this.FoodValue = 0; this.PrestigeValue = 0; } - // End constructors + // endregion constructors - // Functions - // End functions + // region Functions + // endregion functions }