Add: Added Coverage Screenshots And htlmReport.

This commit is contained in:
GabrieleRadice
2026-06-19 21:50:38 +02:00
parent 6aca188aa3
commit d78b8bbd93
316 changed files with 86329 additions and 0 deletions
@@ -0,0 +1,405 @@
<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > DecksCreator</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: DecksCreator (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">DecksCreator</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(7/7)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(57/57)
</span>
</td>
<td class="coverageStat">
<span class="percent">
88.6%
</span>
<span class="absValue">
(70/79)
</span>
</td>
</tr>
<tr>
<td class="name">DecksCreator$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">DecksCreator$2</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">DecksCreator$BuildingCardDefinition</td>
</tr>
<tr>
<td class="name">DecksCreator$TribeCardDefinition</td>
</tr>
<tr>
<td class="name"><strong>Total</strong></td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(9/9)
</span>
</td>
<td class="coverageStat">
<span class="percent">
100%
</span>
<span class="absValue">
(57/57)
</span>
</td>
<td class="coverageStat">
<span class="percent">
88.9%
</span>
<span class="absValue">
(72/81)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Model;
&nbsp;
&nbsp;import com.google.gson.*;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.*;
&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.Model.Cards.TribeCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.CavePaintings;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Hunt;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.ShamanicRitual;
&nbsp;import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
&nbsp;
&nbsp;import java.io.*;
&nbsp;import java.lang.reflect.Type;
&nbsp;import java.util.*;
&nbsp;
&nbsp;/**
&nbsp; * Utility class responsible for loading and creating decks of cards and slots for the game.
&nbsp; * Cards are loaded from JSON resource files and instantiated according to their type and parameters.
&nbsp; */
&nbsp;public class DecksCreator {
&nbsp;
&nbsp; private DecksCreator() {}
&nbsp;
&nbsp; /**
&nbsp; * Loads the tribe card deck for the specified era from the corresponding JSON resource file.
&nbsp; *
&nbsp; * @param era the era number (1, 2, or 3).
&nbsp; * @return a list of {@link TribeCard} objects for the specified era.
&nbsp; * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3.
&nbsp; */
&nbsp; public static List&lt;TribeCard&gt; loadTribeDeckByEra(int era) throws IllegalArgumentException
&nbsp; {
<b class="fc">&nbsp; return switch (era) {</b>
<b class="fc">&nbsp; case 1 -&gt; loadTribeDeck(&quot;/Cards/tribe_era1.json&quot;);</b>
<b class="fc">&nbsp; case 2 -&gt; loadTribeDeck(&quot;/Cards/tribe_era2.json&quot;);</b>
<b class="fc">&nbsp; case 3 -&gt; loadTribeDeck(&quot;/Cards/tribe_era3.json&quot;);</b>
<b class="fc">&nbsp; default -&gt; throw new IllegalArgumentException();</b>
&nbsp; };
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Loads a tribe card deck from the specified JSON resource file path.
&nbsp; *
&nbsp; * @param resourcePath the path to the JSON resource file.
&nbsp; * @return a list of {@link TribeCard} objects defined in the resource file.
&nbsp; * @throws RuntimeException if the resource file is not found or an error occurs while reading it.
&nbsp; */
&nbsp; public static List&lt;TribeCard&gt; loadTribeDeck(String resourcePath) {
<b class="fc">&nbsp; Gson gson = new Gson();</b>
<b class="fc">&nbsp; Type listType = new com.google.gson.reflect.TypeToken&lt;List&lt;TribeCardDefinition&gt;&gt;(){}.getType();</b>
&nbsp;
<b class="fc">&nbsp; InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);</b>
<b class="fc">&nbsp; if (is == null) {</b>
<b class="fc">&nbsp; throw new RuntimeException(&quot;Resource file not found: &quot; + resourcePath);</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; try (Reader reader = new InputStreamReader(is)) {</b>
<b class="fc">&nbsp; List&lt;TribeCardDefinition&gt; definitions = gson.fromJson(reader, listType);</b>
<b class="fc">&nbsp; List&lt;TribeCard&gt; cards = new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; for (TribeCardDefinition def : definitions) {</b>
<b class="fc">&nbsp; cards.add(createCard(def));</b>
&nbsp; }
<b class="fc">&nbsp; return cards;</b>
&nbsp; } catch (IOException e) {
<b class="nc">&nbsp; throw new RuntimeException(&quot;Error loading deck: &quot; + resourcePath, e);</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Loads the building card deck for the specified era, filtering cards from the global building deck.
&nbsp; *
&nbsp; * @param era the era number (1, 2, or 3).
&nbsp; * @return a list of {@link BuildingCard} objects belonging to the specified era.
&nbsp; * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3.
&nbsp; */
&nbsp; public static List&lt;BuildingCard&gt; loadBuildingDeckByEra(int era) throws IllegalArgumentException
&nbsp; {
<b class="fc">&nbsp; if(era&lt;=0 || era&gt;3) throw new IllegalArgumentException();</b>
<b class="fc">&nbsp; return loadBuildingDeck(&quot;/Cards/buildingCards.json&quot;).stream().filter(x-&gt;x.getEra()==era).toList();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Loads the full building card deck from the specified JSON resource file path.
&nbsp; *
&nbsp; * @param resourcePath the path to the JSON resource file.
&nbsp; * @return a list of {@link BuildingCard} objects defined in the resource file.
&nbsp; * @throws RuntimeException if the resource file is not found or an error occurs while reading it.
&nbsp; */
&nbsp; public static List&lt;BuildingCard&gt; loadBuildingDeck(String resourcePath) {
<b class="fc">&nbsp; Gson gson = new Gson();</b>
<b class="fc">&nbsp; Type listType = new com.google.gson.reflect.TypeToken&lt;List&lt;BuildingCardDefinition&gt;&gt;(){}.getType();</b>
&nbsp;
<b class="fc">&nbsp; InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);</b>
<b class="fc">&nbsp; if (is == null) {</b>
<b class="fc">&nbsp; throw new RuntimeException(&quot;Resource file not found: &quot; + resourcePath);</b>
&nbsp; }
&nbsp;
<b class="fc">&nbsp; try (Reader reader = new InputStreamReader(is)) {</b>
<b class="fc">&nbsp; List&lt;BuildingCardDefinition&gt; definitions = gson.fromJson(reader, listType);</b>
<b class="fc">&nbsp; List&lt;BuildingCard&gt; cards = new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; for (BuildingCardDefinition def : definitions) {</b>
<b class="fc">&nbsp; cards.add(createCard(def));</b>
&nbsp; }
<b class="fc">&nbsp; return cards;</b>
&nbsp; } catch (IOException e) {
<b class="nc">&nbsp; throw new RuntimeException(&quot;Error loading deck: &quot; + resourcePath, e);</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Creates and returns the list of slots used as the game board.
&nbsp; * Slots are labeled with the letters A through G.
&nbsp; *
&nbsp; * @return a list of {@link Slot} objects representing the game board.
&nbsp; */
&nbsp; public static List&lt;Slot&gt; loadSlotDeck()
&nbsp; {
<b class="fc">&nbsp; List&lt;Slot&gt; slots = new ArrayList&lt;&gt;();</b>
<b class="fc">&nbsp; char[]chars={&#39;A&#39;,&#39;B&#39;,&#39;C&#39;,&#39;D&#39;,&#39;E&#39;,&#39;F&#39;,&#39;G&#39;};</b>
<b class="fc">&nbsp; for(char c : chars)</b>
<b class="fc">&nbsp; slots.add(new Slot(c));</b>
<b class="fc">&nbsp; return slots;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Instantiates a {@link TribeCard} from the given definition.
&nbsp; * Depending on whether the card is an event or a character, the appropriate subclass is created
&nbsp; * using the type and parameters specified in the definition.
&nbsp; *
&nbsp; * @param def the {@link TribeCardDefinition} containing the card&#39;s type, era, and parameters.
&nbsp; * @return the instantiated {@link TribeCard}.
&nbsp; * @throws IllegalArgumentException if the card type is unknown or the parameters are invalid.
&nbsp; */
&nbsp; private static TribeCard createCard(TribeCardDefinition def) {
<b class="fc">&nbsp; int era = def.era;</b>
<b class="fc">&nbsp; int[] p = def.params.stream().mapToInt(d -&gt; ((Double) d).intValue()).toArray();</b>
<b class="fc">&nbsp; if(def.isEvent)</b>
&nbsp; {
<b class="pc">&nbsp; return switch (def.type) {</b>
<b class="fc">&nbsp; case &quot;Sustenance&quot; -&gt; new Sustenance(def.id,era,p[0]);</b>
<b class="fc">&nbsp; case &quot;Hunt&quot; -&gt; new Hunt(def.id,era,p[0]);</b>
<b class="fc">&nbsp; case &quot;CavePaintings&quot; -&gt; new CavePaintings(def.id,era,p[0],p[1],p[2]);</b>
<b class="fc">&nbsp; case &quot;ShamanicRitual&quot; -&gt; new ShamanicRitual(def.id,era,p[0],p[1]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Unknown event type: &quot; + def.type);</b>
&nbsp; };
&nbsp; }
<b class="pc">&nbsp; return switch (def.type) {</b>
<b class="fc">&nbsp; case &quot;Hunter&quot; -&gt; p.length == 0</b>
<b class="fc">&nbsp; ? new Hunter(def.id,era, def.armed)</b>
<b class="fc">&nbsp; : new Hunter(def.id,era, def.armed, p[0]);</b>
<b class="pc">&nbsp; case &quot;Builder&quot; -&gt; switch (p.length) {</b>
<b class="fc">&nbsp; case 2 -&gt; new Builder(def.id,era, p[0], p[1]);</b>
<b class="fc">&nbsp; case 3 -&gt; new Builder(def.id,era, p[0], p[1], p[2]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Builder: invalid parameters&quot;);</b>
&nbsp; };
<b class="pc">&nbsp; case &quot;Gatherer&quot; -&gt; switch (p.length) {</b>
<b class="fc">&nbsp; case 0 -&gt; new Gatherer(def.id,era);</b>
<b class="fc">&nbsp; case 1 -&gt; new Gatherer(def.id,era, p[0]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Gatherer: invalid parameters&quot;);</b>
&nbsp; };
<b class="pc">&nbsp; case &quot;Artist&quot; -&gt; switch (p.length) {</b>
<b class="fc">&nbsp; case 0 -&gt; new Artist(def.id,era);</b>
<b class="fc">&nbsp; case 1 -&gt; new Artist(def.id,era, p[0]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Artist: invalid parameters&quot;);</b>
&nbsp; };
<b class="pc">&nbsp; case &quot;Inventor&quot; -&gt; switch (p.length) {</b>
<b class="fc">&nbsp; case 1 -&gt; new Inventor(def.id,era, p[0]);</b>
<b class="fc">&nbsp; case 2 -&gt; new Inventor(def.id,era, p[0], p[1]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Inventor: invalid parameters&quot;);</b>
&nbsp; };
<b class="pc">&nbsp; case &quot;Shaman&quot; -&gt; switch (p.length) {</b>
<b class="fc">&nbsp; case 1 -&gt; new Shaman(def.id,era, p[0]);</b>
<b class="fc">&nbsp; case 2 -&gt; new Shaman(def.id,era, p[0], p[1]);</b>
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Shaman: invalid parameters&quot;);</b>
&nbsp; };
<b class="nc">&nbsp; default -&gt; throw new IllegalArgumentException(&quot;Unknown card type: &quot; + def.type);</b>
&nbsp; };
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Instantiates a {@link BuildingCard} from the given definition.
&nbsp; * The appropriate subclass is selected based on the effect ID specified in the definition.
&nbsp; * If no specific subclass matches the effect ID, a base {@link BuildingCard} is created.
&nbsp; *
&nbsp; * @param def the {@link BuildingCardDefinition} containing the card&#39;s effect ID, era, price, prestige value, and parameters.
&nbsp; * @return the instantiated {@link BuildingCard}.
&nbsp; */
&nbsp; private static BuildingCard createCard(BuildingCardDefinition def) {
<b class="pc">&nbsp; return switch (def.effectId) {</b>
<b class="fc">&nbsp; case 0 -&gt; new Building0(def.id,def.era, def.price, def.prestigeValue);</b>
<b class="fc">&nbsp; case 1 -&gt; new Building1(def.id,def.era, def.price, def.prestigeValue, CharacterType.valueOf(((String) def.params.get(0)).toUpperCase()));</b>
<b class="fc">&nbsp; case 4 -&gt; new Building4(def.id,def.era, def.price, def.prestigeValue);</b>
<b class="fc">&nbsp; case 8 -&gt; new Building8(def.id,def.era, def.price, def.prestigeValue);</b>
<b class="fc">&nbsp; case 10 -&gt; new Building10(def.id,def.era, def.price, def.prestigeValue);</b>
<b class="fc">&nbsp; case 11 -&gt; new Building11(def.id,def.era, def.price, def.prestigeValue, CharacterType.valueOf(((String) def.params.get(0)).toUpperCase()), ((Double) def.params.get(1)).intValue());</b>
<b class="fc">&nbsp; case 13 -&gt; new Building13(def.id,def.era, def.price, def.prestigeValue);</b>
<b class="fc">&nbsp; default -&gt; new BuildingCard(def.id,def.effectId, def.era, def.price, def.prestigeValue);</b>
&nbsp; };
&nbsp;
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Internal data class representing the raw definition of a tribe card as loaded from a JSON file.
&nbsp; * Contains the card identifier, type, era, whether it is armed, whether it is an event card,
&nbsp; * and a list of additional parameters.
&nbsp; */
&nbsp; private static class TribeCardDefinition {
&nbsp; String id;
&nbsp; String type;
&nbsp; int era;
&nbsp; boolean armed;
&nbsp; boolean isEvent;
&nbsp; List&lt;Object&gt; params; // Object to support mixed boolean and numeric parameters from JSON
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Internal data class representing the raw definition of a building card as loaded from a JSON file.
&nbsp; * Contains the card identifier, effect ID, era, price, prestige value, and a list of additional parameters.
&nbsp; */
&nbsp; private static class BuildingCardDefinition {
&nbsp; String id;
&nbsp; int effectId;
&nbsp; int era;
&nbsp; int price;
&nbsp; int prestigeValue;
&nbsp; List&lt;Object&gt; params; // Object to support mixed boolean and numeric parameters from JSON
&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-14 21:53</div>
</div>
</body>
</html>