Files
Progetto-ingegneria-del-sof…/deliverables/Coverage/htmlReport/ns-c/sources/source-4.html
T
2026-06-19 21:50:38 +02:00

320 lines
9.7 KiB
HTML

<!DOCTYPE html>
<html id="htmlId">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Coverage Report > NetworkEvent</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.Network</a>
</div>
<h1>Coverage Summary for Class: NetworkEvent (it.polimi.ingsw.gc14.Network)</h1>
<table class="coverageStats">
<tr>
<th class="name">Class</th>
<th class="coverageStat
">
Class, %
</th>
<th class="coverageStat
">
Method, %
</th>
<th class="coverageStat
">
Branch, %
</th>
<th class="coverageStat
">
Line, %
</th>
</tr>
<tr>
<td class="name">NetworkEvent</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/1)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/10)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/2)
</span>
</td>
<td class="coverageStat">
<span class="percent">
0%
</span>
<span class="absValue">
(0/19)
</span>
</td>
</tr>
</table>
<br/>
<br/>
<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package it.polimi.ingsw.gc14.Network;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.Controller.GameController;
&nbsp;import it.polimi.ingsw.gc14.ErrorType;
&nbsp;import it.polimi.ingsw.gc14.Model.Game;
&nbsp;import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
&nbsp;import it.polimi.ingsw.gc14.Model.MiniModel;
&nbsp;import it.polimi.ingsw.gc14.Model.OrderLogicCard;
&nbsp;import it.polimi.ingsw.gc14.Model.Player;
&nbsp;import it.polimi.ingsw.gc14.Model.Slot;
&nbsp;
&nbsp;import java.io.Serializable;
&nbsp;import java.util.ArrayList;
&nbsp;import java.util.List;
&nbsp;import java.util.Map;
&nbsp;
&nbsp;/**
&nbsp; * Represents an event sent over the network.
&nbsp; *
&nbsp; * &lt;p&gt;A network event contains the information required to identify
&nbsp; * the requested action, determine whether it produced an error,
&nbsp; * and apply it either to the server-side {@link GameController}
&nbsp; * or to the client-side {@link MiniModel}.
&nbsp; */
&nbsp;public abstract class NetworkEvent implements Serializable {
&nbsp;
&nbsp; /** The error type associated with this event; set when the event failed to apply. */
&nbsp; protected ErrorType errorType;
&nbsp;
&nbsp; /**
&nbsp; * Returns the error type associated with this event.
&nbsp; *
&nbsp; * @return the error type, or {@code null} if no error occurred.
&nbsp; */
&nbsp; public ErrorType getErrorType() {
<b class="nc">&nbsp; return errorType;</b>
&nbsp; }
&nbsp; /**
&nbsp; * Username of the player requesting the event.
&nbsp; */
&nbsp; protected String username;
&nbsp;
&nbsp; /**
&nbsp; * Returns the username of the player requesting the event.
&nbsp; *
&nbsp; * @return the username associated with the event.
&nbsp; */
&nbsp; public String getUsername() {
<b class="nc">&nbsp; return username;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Type of the network event.
&nbsp; */
&nbsp; protected EventType eventType;
&nbsp;
&nbsp; /**
&nbsp; * Map associating each occupied slot with the corresponding player.
&nbsp; */
&nbsp; protected Map&lt;Slot, Player&gt; slotPlayerMap;
&nbsp;
&nbsp; /**
&nbsp; * Order logic card used to manage the player turn order.
&nbsp; */
&nbsp; protected OrderLogicCard orderLogicCard;
&nbsp;
&nbsp; /**
&nbsp; * Current state of the game associated with the event.
&nbsp; */
&nbsp; protected CurrentState currentState;
&nbsp;
&nbsp; /**
&nbsp; * List of all players.
&nbsp; */
&nbsp; protected List&lt;Player&gt; playerList;
&nbsp;
&nbsp; /**
&nbsp; * Usernames of players currently disconnected from the game.
&nbsp; * Sent with every event so clients always have an up-to-date list.
&nbsp; */
&nbsp; protected ArrayList&lt;String&gt; disconnectedPlayers;
&nbsp;
&nbsp; /**
&nbsp; * Populates this event with the current game state so clients can
&nbsp; * update their local model after receiving it.
&nbsp; * Subclasses that carry extra state (available totems, etc.) override
&nbsp; * this method and call {@code super} first.
&nbsp; *
&nbsp; * @param game the current game model.
&nbsp; * @param disconnectedUsernames usernames of currently disconnected players.
&nbsp; */
&nbsp; public void enrichWithGameState(Game game, ArrayList&lt;String&gt; disconnectedUsernames) {
<b class="nc">&nbsp; setData(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers());</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Sets the game data associated with this network event.
&nbsp; *
&nbsp; * @param slotPlayerMap the map associating each slot with the player occupying it.
&nbsp; * @param orderLogicCard the order logic card used to manage turn order.
&nbsp; * @param currentState the current state of the game.
&nbsp; * @param playerList the list of the actual state of the players
&nbsp; */
&nbsp; public void setData(Map&lt;Slot, Player&gt; slotPlayerMap,
&nbsp; OrderLogicCard orderLogicCard,
&nbsp; CurrentState currentState,
&nbsp; List&lt;Player&gt; playerList) {
<b class="nc">&nbsp; this.slotPlayerMap = slotPlayerMap;</b>
<b class="nc">&nbsp; this.orderLogicCard = orderLogicCard;</b>
<b class="nc">&nbsp; this.currentState = currentState;</b>
<b class="nc">&nbsp; this.playerList = playerList;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Returns the type of this event.
&nbsp; *
&nbsp; * @return the event type.
&nbsp; */
&nbsp; public EventType getEventType() {
<b class="nc">&nbsp; return eventType;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Flag indicating whether the event could not be applied successfully.
&nbsp; */
&nbsp; protected boolean isError;
&nbsp;
&nbsp; /**
&nbsp; * Returns whether the event represents an error.
&nbsp; *
&nbsp; * @return {@code true} if the event could not be applied successfully,
&nbsp; * {@code false} otherwise.
&nbsp; */
&nbsp; public boolean isError() {
<b class="nc">&nbsp; return isError;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Sets whether the event represents an error.
&nbsp; *
&nbsp; * @param isError {@code true} if the event could not be applied successfully,
&nbsp; * {@code false} otherwise.
&nbsp; */
&nbsp; public void setIsError(boolean isError) {
<b class="nc">&nbsp; this.isError = isError;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Overrides the error type for this event.
&nbsp; *
&nbsp; * @param errorType the error type to set.
&nbsp; */
&nbsp; public void setErrorType(ErrorType errorType) {
<b class="nc">&nbsp; this.errorType = errorType;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Constructs a network event.
&nbsp; *
&nbsp; * @param username the username of the player requesting the event.
&nbsp; * @param eventType the type of the event.
&nbsp; * @param isError {@code true} if the event represents an error,
&nbsp; * {@code false} otherwise.
&nbsp; */
<b class="nc">&nbsp; protected NetworkEvent(String username, EventType eventType, boolean isError, ErrorType errorType) {</b>
<b class="nc">&nbsp; this.username = username;</b>
<b class="nc">&nbsp; this.eventType = eventType;</b>
<b class="nc">&nbsp; this.isError = isError;</b>
<b class="nc">&nbsp; this.errorType = errorType;</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Returns a textual description of the event and its outcome.
&nbsp; *
&nbsp; * @return a string describing the event type and whether it represents an error.
&nbsp; */
&nbsp; @Override
&nbsp; public String toString() {
<b class="nc">&nbsp; if (isError) {</b>
<b class="nc">&nbsp; return &quot;ERROR: &quot; + eventType;</b>
&nbsp; } else {
<b class="nc">&nbsp; return &quot;ACTION: &quot; + eventType;</b>
&nbsp; }
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Applies this event to the specified server-side game controller.
&nbsp; *
&nbsp; * @param gameController the game controller on which the event must be applied.
&nbsp; * @return {@code true} if the event is applied successfully,
&nbsp; * {@code false} otherwise.
&nbsp; */
&nbsp; public abstract boolean apply(GameController gameController);
&nbsp;
&nbsp; /**
&nbsp; * Applies this event to the specified client-side mini model.
&nbsp; *
&nbsp; * @param model the mini model on which the event must be applied.
&nbsp; * @return {@code true} if the event is applied successfully,
&nbsp; * {@code false} otherwise.
&nbsp; */
&nbsp; public abstract boolean apply(MiniModel model);
&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>