public final class Broadcast extends Object
Broadcast
stores a mapping from users to a list of responses.
The server backend uses a broadcast to send messages to clients.
You do not need to modify this file.Modifier and Type | Method and Description |
---|---|
static Broadcast |
connected(String recipient)
Creates a
Broadcast for the case when a user first connects to
the server and should be informed of their new nickname |
static Broadcast |
disconnected(String user,
Set<String> recipients)
Creates a
Broadcast for the case when a user disconnects from the
server and other clients should be informed of this fact |
boolean |
equals(Object o) |
static Broadcast |
error(Command command,
ServerError error)
Creates a
Broadcast for the case where a client's Command is invalid, and the client should be informed. |
Map<Integer,List<String>> |
getResponses(ServerModelApi model)
Associates the stored responses with the user IDs of the recipients.
|
int |
hashCode() |
static Broadcast |
names(Command command,
Set<String> recipients,
String owner)
A specialized method for creating a
Broadcast in the event that
a user is added to a channel as the result of a JoinCommand or
InviteCommand . |
static Broadcast |
okay(Command command,
Set<String> recipients)
Creates a
Broadcast for the general case where a client's
Command is accepted by the server and should be relayed to the
appropriate clients. |
String |
toString() |
public static Broadcast okay(Command command, Set<String> recipients)
Broadcast
for the general case where a client's
Command
is accepted by the server and should be relayed to the
appropriate clients.command
- The Command
whose effects to broadcastrecipients
- The set of user names of clients who should receive
the broadcast from the serverBroadcast
representing a set of responses to sendpublic static Broadcast error(Command command, ServerError error)
Broadcast
for the case where a client's Command
is invalid, and the client should be informed.command
- The command which caused the errorerror
- The ServerError
that the command causedBroadcast
representing the response to sendIllegalArgumentException
- if error value is OKAY
public static Broadcast connected(String recipient)
Broadcast
for the case when a user first connects to
the server and should be informed of their new nicknamerecipient
- The automatically generated nickname for the clientBroadcast
to the new clientpublic static Broadcast disconnected(String user, Set<String> recipients)
Broadcast
for the case when a user disconnects from the
server and other clients should be informed of this factuser
- 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.Broadcast
representing the response to sendpublic static Broadcast names(Command command, Set<String> recipients, String owner)
Broadcast
in the event that
a user is added to a channel as the result of a JoinCommand
or
InviteCommand
. The resulting Broadcast informs the relevant
client of the nicknames of all other users in the channel.command
- The command issued by the clientrecipients
- 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 ownerBroadcast
representing the responses to sendIllegalArgumentException
- if command
is not an instance
of JoinCommand
or InviteCommand
public Map<Integer,List<String>> getResponses(ServerModelApi model)
ServerBackend
before dispatching
the Broadcast
; you should not call this yourself.model
- A class conforming to ServerModelApi
which can be
used to look up user IDs.ServerBackend