Package org.cis1200
Class Broadcast
java.lang.Object
org.cis1200.Broadcast
A
Broadcast
stores a mapping from users to a list of responses
that should be sent to each user.
The server backend uses a broadcast to send messages to clients to inform
them of relevant events in their channels. For instance, many chat services
inform you when someone has been removed from a chat that you're in.
You do not need to modify this file but you will need to read and understand
how it works to complete the assignment.-
Method Summary
Modifier and TypeMethodDescriptionstatic Broadcast
Creates aBroadcast
for the case when a user first connects to the server and should be informed of their new nicknamestatic Broadcast
disconnected
(String user, Collection<String> recipients) Creates aBroadcast
for the case when a user disconnects from the server and other clients should be informed of this fact.boolean
static Broadcast
error
(Command command, ServerResponse error) Creates aBroadcast
for the case where a client'sCommand
is invalid, and the client should be informed.getResponses
(ServerModel model) You should not call this method yourself.int
hashCode()
static Broadcast
names
(Command command, Collection<String> recipients, String owner) A specialized method for creating aBroadcast
in the event that a user is added to a channel as the result of aJoinCommand
orInviteCommand
.static Broadcast
okay
(Command command, Collection<String> recipients) Creates aBroadcast
for the general case where a client'sCommand
is accepted by the server and should be relayed to the appropriate clients.toString()
-
Method Details
-
okay
Creates aBroadcast
for the general case where a client'sCommand
is accepted by the server and should be relayed to the appropriate clients.- Parameters:
command
- TheCommand
whose effects to broadcastrecipients
- The set of usernames of clients who should receive the broadcast from the server- Returns:
- A
Broadcast
representing a set of responses to send
-
error
Creates aBroadcast
for the case where a client'sCommand
is invalid, and the client should be informed.- Parameters:
command
- The command which caused the errorerror
- TheServerResponse
that the command caused- Returns:
- A
Broadcast
representing the response to send - Throws:
IllegalArgumentException
- if error value isOKAY
-
connected
Creates aBroadcast
for the case when a user first connects to the server and should be informed of their new nickname- Parameters:
recipient
- The automatically generated nickname for the client- Returns:
- A
Broadcast
to the new client
-
disconnected
Creates aBroadcast
for the case when a user disconnects from the server and other clients should be informed of this fact.- Parameters:
user
- The nickname of the disconnected userrecipients
- A set of nicknames of clients who should be informed of the user's disconnection. Should not include the user who disconnected.- Returns:
- A
Broadcast
representing the response to send
-
names
A specialized method for creating aBroadcast
in the event that a user is added to a channel as the result of aJoinCommand
orInviteCommand
. The resulting Broadcast informs the relevant client of the nicknames of all other users in the channel.- Parameters:
command
- The command issued by the client (Invite or Join)recipients
- A set of nicknames of the other users in the channel which the user is joining, and to whom the command should be relayed.owner
- The nickname of the channel's owner- Returns:
- A
Broadcast
representing the responses to send - Throws:
IllegalArgumentException
- ifcommand
is not an instanceofJoinCommand
orInviteCommand
-
getResponses
You should not call this method yourself. Associates the stored responses with the user IDs of the recipients. This * function will be called by theServerBackend
before dispatching theBroadcast
.- Parameters:
model
- A data structure representing the state of the server- Returns:
- a mapping from user ID to a list of response strings that should be
delivered by the
ServerBackend
-
equals
-
hashCode
public int hashCode() -
toString
-