java.lang.Object
it.polimi.ingsw.am13.client.chat.Chat
This class stores all the chat messages that meet the following requirements:
-they have thisPlayer as a sender or as one of the receivers
-the number of receivers is either one, or number of players-1 (all the players aside from the sender)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<List<PlayerLobby>, List<ChatMessage>> This is the map that stores the chat messages, associating to every valid list of PlayerLobby a list of ChatMessageprivate final List
<PlayerLobby> All the other players who are in the same match as thisPlayerprivate final PlayerLobby
The player who is associated (owns) to a specific instance of this class -
Constructor Summary
ConstructorsConstructorDescriptionChat
(List<PlayerLobby> players, PlayerLobby thisPlayer) This constructor sets the value of thisPlayer and otherPlayers, and initializes the chat by associating an empty list to each valid list of PlayerLobby -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMessage
(List<PlayerLobby> receivers, ChatMessage chatMessage) Adds the chatMessage to the appropriate entry of the chat.getChatWith
(List<PlayerLobby> receivers)
-
Field Details
-
chat
This is the map that stores the chat messages, associating to every valid list of PlayerLobby a list of ChatMessage -
thisPlayer
The player who is associated (owns) to a specific instance of this class -
otherPlayers
All the other players who are in the same match as thisPlayer
-
-
Constructor Details
-
Chat
This constructor sets the value of thisPlayer and otherPlayers, and initializes the chat by associating an empty list to each valid list of PlayerLobby- Parameters:
players
- all the players of the match thisPlayer is inthisPlayer
- the player who is associated to a specific instance of this class
-
-
Method Details
-
addMessage
Adds the chatMessage to the appropriate entry of the chat. This means that if the sender is thisPlayer the message is added to the chat with the receivers; while if thisPlayer is one of the receivers the message is added to the chat with sender, or the chat between all the players if the receivers are all the players who are not the sender. This method assumes that the parameters respect the required format, relying on the checks performed on the server (InvalidReceiversException). It does not check in a complete manner that the parameters are correct.- Parameters:
receivers
- of the messagechatMessage
- that needs to be added to the chat
-
getChatWith
- Parameters:
receivers
- Receivers indicating the specific chatroom whose messages are to be retrieved- Returns:
- The list of messages of the chatroom with the specified receivers, or null if no chat with those receivers is present
-