Files
Progetto-ingegneria-del-sof…/deliverables/Coverage/htmReport/ns-3/sources/source-6.html
T
2026-06-19 22:57:43 +02:00

527 lines
20 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > Player</title>
<style type="text/css">
@import "../../css/coverage.css";
@import "../../css/idea.min.css";
</style>
<script type="text/javascript" src="../../js/highlight.min.js"></script>
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>
<body>
<div class="content">
<div class="breadCrumbs">
Current scope: <a href="../../index.html">all classes</a>
<span class="separator">|</span>
<a href="../index.html">it.polimi.ingsw.gc14.Model</a>
</div>
<h1>Coverage Summary for Class: Player (it.polimi.ingsw.gc14.Model)</h1>
<table class="coverageStats">
<tr>
<th class="name">Class</th>
<th class="coverageStat
">
Method, %
</th>
<th class="coverageStat
">
Branch, %
</th>
<th class="coverageStat
">
Line, %
</th>
</tr>
<tr>
<td class="name">Player</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(22/22)
</span>
</td>
<td class="coverageStat">
<span class="percent">
84.5%
</span>
<span class="absValue">
(49/58)
</span>
</td>
<td class="coverageStat">
<span class="percent">
98.1%
</span>
<span class="absValue">
(102/104)
</span>
</td>
</tr>
<tr>
<td class="name">Player$1</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(1/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(1/1)
</span>
</td>
</tr>
<tr>
<td class="name"><strong>Total</strong></td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(23/23)
</span>
</td>
<td class="coverageStat">
<span class="percent">
84.5%
</span>
<span class="absValue">
(49/58)
</span>
</td>
<td class="coverageStat">
<span class="percent">
98.1%
</span>
<span class="absValue">
(103/105)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
&nbsp;import it.polimi.ingsw.gc14.View.TUI.AsciiTable;
&nbsp;
&nbsp;import java.io.Serializable;
&nbsp;import java.util.ArrayList;
&nbsp;import java.util.Arrays;
&nbsp;import java.util.Map;
&nbsp;import java.util.stream.Collectors;
&nbsp;
&nbsp;import static it.polimi.ingsw.gc14.View.TUI.BorderStyle.*;
&nbsp;
&nbsp;/**
&nbsp; * Default Player class; contains all identifiers and methods needed.
&nbsp; */
&nbsp;public class Player implements Serializable {
&nbsp; /**
&nbsp; * The maximum length allowed for the username string.
&nbsp; */
&nbsp; private static final int MAX_USERNAME_LENGTH = 10;
&nbsp;
&nbsp; /**
&nbsp; * Identifier for the {@code Player} when displaying the game through the GUI.
&nbsp; * @see Totems
&nbsp; */
&nbsp; private Totems totem;
&nbsp;
&nbsp; /**
&nbsp; * Unique string identifier for players; must not be {@code null} and must not
&nbsp; * exceed {@link #MAX_USERNAME_LENGTH} otherwise an {@link IllegalArgumentException} will be thrown
&nbsp; * when the {@link #Player(String) constructor} is called.
&nbsp; */
&nbsp; private final String userName;
&nbsp;
&nbsp; /**
&nbsp; * Getter for the private attribute {@link #userName}.
&nbsp; * @return {@code String} - The UserName
&nbsp; */
&nbsp; public String getUserName() {
<b class="fc">&nbsp; return userName;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Returns the totem assigned to this player.
&nbsp; *
&nbsp; * @return this player&#39;s totem.
&nbsp; */
&nbsp; public Totems getTotem() {
<b class="fc">&nbsp; return totem;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Counts the total {@link it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character Character Cards}
&nbsp; * the player currently possesses.
&nbsp; * @return {@code int} - Total Character Cards.
&nbsp; */
&nbsp; public int getTotCharacters() {
<b class="fc">&nbsp; return Arrays.stream(CharacterType.values())</b>
<b class="fc">&nbsp; .mapToInt(this::getNType)</b>
<b class="fc">&nbsp; .sum();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Counts the total number of cards of the specified {@link it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType Character Type}.
&nbsp; * Character Type must not be {@code null}
&nbsp; * @param type the Character Type to be Counted.
&nbsp; * @return {@code int} - Total number of cards of given {@code type}.
&nbsp; */
&nbsp; public int getNType(CharacterType type) {
<b class="pc">&nbsp; return switch (type) {</b>
<b class="fc">&nbsp; case ARTIST -&gt; artists.size();</b>
<b class="fc">&nbsp; case INVENTOR -&gt; inventors.size();</b>
<b class="fc">&nbsp; case HUNTER -&gt; hunters.size();</b>
<b class="fc">&nbsp; case BUILDER -&gt; builders.size();</b>
<b class="fc">&nbsp; case SHAMAN -&gt; shamans.size();</b>
<b class="fc">&nbsp; case GATHERER -&gt; gatherers.size();</b>
&nbsp; };
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current {@link BuildingCard Building Cards} in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;BuildingCard&gt; buildingCards;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Artist Artist} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Artist&gt; artists;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Builder Builder} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Builder&gt; builders;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Inventor Inventor} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Inventor&gt; inventors;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Gatherer Gatherer} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Gatherer&gt; gatherers;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Shaman Shaman} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Shaman&gt; shamans;
&nbsp;
&nbsp; /**
&nbsp; * The current {@link Hunter Hunter} cards in the player&#39;s deck.
&nbsp; */
&nbsp; private final ArrayList&lt;Hunter&gt; hunters;
&nbsp;
&nbsp; /** @return this player&#39;s building cards. */
<b class="fc">&nbsp; public ArrayList&lt;BuildingCard&gt; getBuildingCards() { return buildingCards; }</b>
&nbsp; /** @return this player&#39;s Artist character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Artist&gt; getArtists() { return artists; }</b>
&nbsp; /** @return this player&#39;s Builder character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Builder&gt; getBuilders() { return builders; }</b>
&nbsp; /** @return this player&#39;s Inventor character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Inventor&gt; getInventors() { return inventors; }</b>
&nbsp; /** @return this player&#39;s Gatherer character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Gatherer&gt; getGatherers() { return gatherers; }</b>
&nbsp; /** @return this player&#39;s Shaman character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Shaman&gt; getShamans() { return shamans; }</b>
&nbsp; /** @return this player&#39;s Hunter character cards. */
<b class="fc">&nbsp; public ArrayList&lt;Hunter&gt; getHunters() { return hunters; }</b>
&nbsp;
&nbsp; /**
&nbsp; * The current amount of {@code Food} the Player possesses.
&nbsp; * Cannot be negative.
&nbsp; */
&nbsp; private int foodValue;
&nbsp;
&nbsp; /**
&nbsp; * Getter for the private attribute {@link #foodValue}.
&nbsp; * @return {@code int} - The amount of Food the player possesses.
&nbsp; */
&nbsp; public int getFoodValue() {
<b class="fc">&nbsp; return foodValue;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * The current amount of {@code Prestige} the Player possesses.
&nbsp; */
&nbsp; private int prestigeValue;
&nbsp;
&nbsp; /**
&nbsp; * Getter for the private attribute {@link #prestigeValue}.
&nbsp; * @return {@code int} - The amount of Prestige the Player possesses.
&nbsp; */
&nbsp; public int getPrestigeValue() {
<b class="fc">&nbsp; return prestigeValue;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Adds {@code value} amount of Food to the Player.
&nbsp; * @param value The amount of Food to be added. Should be non-negative.
&nbsp; * @see #foodValue
&nbsp; */
&nbsp; public void addFood(int value){
<b class="fc">&nbsp; this.foodValue += value;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Sets the totem for this player.
&nbsp; *
&nbsp; * @param totem the totem to assign.
&nbsp; */
&nbsp; public void setTotem(Totems totem) {
<b class="fc">&nbsp; this.totem = totem;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Removes {@code value} amount of Food from the Player.
&nbsp; * {@link #foodValue} cannot go negative: returns {@code false} if
&nbsp; * {@code value} exceeds the current food and leaves the value unchanged.
&nbsp; *
&nbsp; * @param value The amount of Food to be removed. Should be non-negative.
&nbsp; * @return {@code true} if the Food is successfully removed, {@code false} otherwise.
&nbsp; * @see #foodValue
&nbsp; */
&nbsp; public boolean removeFood(int value){
<b class="fc">&nbsp; if(value &gt; this.foodValue){</b>
<b class="fc">&nbsp; return false;</b>
&nbsp; }
<b class="fc">&nbsp; this.foodValue -= value;</b>
<b class="fc">&nbsp; return true;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Adds {@code value} amount of Prestige to the Player.
&nbsp; * @param value The amount of Prestige to be added. Should be non-negative.
&nbsp; * @see #prestigeValue
&nbsp; */
&nbsp; public void addPrestige(int value){
<b class="fc">&nbsp; this.prestigeValue += value;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Removes {@code value} amount of Prestige from the Player.
&nbsp; * @param value The amount of Prestige to be removed. Should be non-negative.
&nbsp; * @see #prestigeValue
&nbsp; */
&nbsp; public void removePrestige(int value){
<b class="fc">&nbsp; this.prestigeValue -= value;</b>
&nbsp; }
&nbsp;
&nbsp;
&nbsp;
&nbsp; /**
&nbsp; * Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}.
&nbsp; *
&nbsp; * @param userName Unique String identifier for a Player.
&nbsp; * @throws IllegalArgumentException when {@code userName} is empty or exceeds {@link #MAX_USERNAME_LENGTH},
&nbsp; * with message:
&nbsp; * &lt;pre&gt;{@code UserName is empty or exceeds maximum permitted length.}&lt;/pre&gt;
&nbsp; *
&nbsp; * @see #userName
&nbsp; * @see #MAX_USERNAME_LENGTH
&nbsp; */
<b class="fc">&nbsp; public Player(String userName) throws IllegalArgumentException {</b>
<b class="fc">&nbsp; if(userName.isEmpty() || userName.length() &gt; MAX_USERNAME_LENGTH) {</b>
<b class="fc">&nbsp; throw new IllegalArgumentException(&quot;UserName is empty or exceeds maximum permitted length.&quot;);</b>
&nbsp; }
<b class="fc">&nbsp; this.userName = userName;</b>
&nbsp;
<b class="fc">&nbsp; this.inventors = new ArrayList &lt;&gt;();</b>
<b class="fc">&nbsp; this.builders = new ArrayList &lt;&gt;();</b>
<b class="fc">&nbsp; this.gatherers = new ArrayList &lt;&gt;();</b>
<b class="fc">&nbsp; this.shamans = new ArrayList &lt;&gt;();</b>
<b class="fc">&nbsp; this.hunters = new ArrayList &lt;&gt;();</b>
<b class="fc">&nbsp; this.artists = new ArrayList&lt;&gt;();</b>
&nbsp;
<b class="fc">&nbsp; this.buildingCards = new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; this.foodValue = 0;</b>
<b class="fc">&nbsp; this.prestigeValue = 0;</b>
<b class="fc">&nbsp; this.totem = null;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Checks equality between this {@code Player} and another object.
&nbsp; * Two players are equal if and only if they share the same {@code userName}.
&nbsp; *
&nbsp; * @param obj the object to compare with.
&nbsp; * @return {@code true} if {@code obj} is a {@code Player} with the same username; {@code false} otherwise.
&nbsp; */
&nbsp; @Override
&nbsp; public boolean equals(Object obj) {
<b class="fc">&nbsp; if (this == obj) return true;</b>
<b class="pc">&nbsp; if (!(obj instanceof Player)) return false;</b>
<b class="fc">&nbsp; return userName.equals(((Player) obj).userName);</b>
&nbsp; }
&nbsp;
&nbsp; @Override
&nbsp; public int hashCode() {
<b class="fc">&nbsp; return userName.hashCode();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Prints the {@code Player}&#39;s attributes for the {@code Board}&#39;s representation.
&nbsp; * Uses the {@code UNICODE} border style.
&nbsp; * &lt;p&gt;&lt;b&gt;Includes:&lt;/b&gt;
&nbsp; * &lt;li&gt;{@link #foodValue Food}
&nbsp; * &lt;li&gt;{@link #prestigeValue Prestige}
&nbsp; * &lt;li&gt;{@link #artists Artists}
&nbsp; * &lt;li&gt;{@link #builders Builders}
&nbsp; * &lt;li&gt;{@link #gatherers Gatherers}
&nbsp; * &lt;li&gt;{@link #shamans Shamans}
&nbsp; * &lt;li&gt;{@link #inventors Inventors}
&nbsp; * &lt;li&gt;{@link #hunters Hunters}
&nbsp; * &lt;li&gt;{@link #buildingCards Buildings}
&nbsp; * &lt;/p&gt;
&nbsp; * @return {@code String} - A string representation of the {@code Player}&#39;s attributes.
&nbsp; * @see it.polimi.ingsw.gc14.View.TUI.BorderStyle BorderStyle
&nbsp; */
&nbsp; @Override
&nbsp; public String toString() {
&nbsp; int last;
&nbsp;
<b class="fc">&nbsp; var table = new AsciiTable(ROUNDED, 1);</b>
&nbsp;
<b class="pc">&nbsp; String totemStr = (this.totem != null) ? &quot; (&quot; + this.totem + &quot;)&quot; : &quot;&quot;;</b>
<b class="fc">&nbsp; table.addHeader(this.getUserName() + totemStr + &quot; | \uD83C\uDF56:&quot; + this.getFoodValue() + &quot; | \uD83C\uDFC5:&quot; + this.getPrestigeValue());</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp;
<b class="fc">&nbsp; if(!this.hunters.isEmpty()){</b>
<b class="fc">&nbsp; last = 6;</b>
&nbsp; }
<b class="fc">&nbsp; else if(!this.inventors.isEmpty()){</b>
<b class="fc">&nbsp; last = 5;</b>
&nbsp; }
<b class="fc">&nbsp; else if(!this.shamans.isEmpty()){</b>
<b class="fc">&nbsp; last = 4;</b>
&nbsp; }
<b class="fc">&nbsp; else if(!this.gatherers.isEmpty()){</b>
<b class="fc">&nbsp; last = 3;</b>
&nbsp; }
<b class="fc">&nbsp; else if(!this.builders.isEmpty()){</b>
<b class="fc">&nbsp; last = 2;</b>
&nbsp; }
<b class="fc">&nbsp; else if(!this.artists.isEmpty()){</b>
<b class="fc">&nbsp; last = 1;</b>
&nbsp; }
&nbsp; else{
<b class="fc">&nbsp; last = 0;</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; if(last == 0){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
<b class="fc">&nbsp; table.addRow(&quot;CHARACTERS&quot;);</b>
<b class="fc">&nbsp; if(!this.artists.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.artists.size() + &quot; Artists: \uD83C\uDFA8:&quot; + this.artists.size());</b>
<b class="pc">&nbsp; if(last == 1){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
&nbsp; }
&nbsp;
<b class="fc">&nbsp; if(!this.builders.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.builders.size() + &quot; Builders: &quot; + &quot;\uD83D\uDD28:&quot; + this.builders.stream().mapToInt(Builder::getReductionValue).sum() + &quot; \uD83C\uDFC5:&quot; + this.builders.stream().mapToInt(Builder::getPrestigeValue).sum());</b>
<b class="pc">&nbsp; if(last == 2){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
&nbsp; }
&nbsp;
<b class="fc">&nbsp; if(!this.gatherers.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.gatherers.size() + &quot; Gatherers: \uD83C\uDF56:&quot; + 3*this.gatherers.size());</b>
<b class="pc">&nbsp; if(last == 3){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
&nbsp; }
&nbsp;
<b class="fc">&nbsp; if(!this.shamans.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.shamans.size() + &quot; Shamans: &quot; + &quot;\uD83C\uDF1F:&quot; + this.shamans.stream().mapToInt(Shaman::getIcon).sum());</b>
<b class="pc">&nbsp; if(last == 4){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
&nbsp; }
&nbsp;
<b class="fc">&nbsp; if(!this.inventors.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.inventors.size() + &quot; Inventors: &quot; + this.inventors.stream()</b>
<b class="fc">&nbsp; .collect(Collectors.groupingBy(</b>
&nbsp; Inventor::getIcon,
<b class="fc">&nbsp; Collectors.counting()</b>
&nbsp; ))
<b class="fc">&nbsp; .entrySet().stream()</b>
<b class="fc">&nbsp; .sorted(Map.Entry.comparingByKey())</b>
<b class="fc">&nbsp; .map(e -&gt; e.getKey() + &quot;:&quot; + e.getValue())</b>
<b class="fc">&nbsp; .collect(Collectors.joining(&quot;, &quot;)));</b>
<b class="pc">&nbsp; if(last == 5){</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp;
<b class="fc">&nbsp; if(!this.hunters.isEmpty()){</b>
<b class="fc">&nbsp; table.addRow(this.hunters.size() + &quot; Hunters: \uD83C\uDF56&quot; + this.hunters.stream().filter(Hunter::getIcon).count());</b>
<b class="fc">&nbsp; table.addSeparator();</b>
&nbsp; }
<b class="fc">&nbsp; table.addSeparator();</b>
<b class="fc">&nbsp; table.addRow(&quot;BUILDING CARDS&quot; +</b>
<b class="pc">&nbsp; (this.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum() != 0</b>
<b class="nc">&nbsp; ? &quot; \uD83C\uDFC5:&quot; + this.buildingCards.stream().mapToInt(BuildingCard::getPrestigeValue).sum()</b>
<b class="fc">&nbsp; : &quot;&quot;));</b>
<b class="pc">&nbsp; if(!this.buildingCards.isEmpty()){</b>
<b class="nc">&nbsp; table.addRow(this.buildingCards.size() + &quot; Buildings: &quot; + this.buildingCards.stream().map(BuildingCard::toStringPlayer).collect(Collectors.joining(&quot;, &quot;)));</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; return table.build();</b>
&nbsp; }
&nbsp;}
</code>
</pre>
</div>
<script type="text/javascript">
(function() {
var msie = false, msie9 = false;
/*@cc_on
msie = true;
@if (@_jscript_version >= 9)
msie9 = true;
@end
@*/
if (!msie || msie && msie9) {
hljs.highlightAll()
hljs.initLineNumbersOnLoad();
}
})();
</script>
<div class="footer">
<div style="float:right;">generated on 2026-06-19 22:53</div>
</div>
</body>
</html>