Package org.cis1200
Class Response
java.lang.Object
org.cis1200.Response
- All Implemented Interfaces:
Comparable<Response>
A message that the server sends to a client in response to a command
Each response has two parts: the userId for the recipient of the response
and a string containing the text of the message itself. For example
The server should construct instances of this class using the static
methods that automatically create the message text from the arguments
of the message.
{#link Response#okay} - A Command processed successfully
{#link Response#error} - A Command produced an error
{#link Response#connected} - A new user connected to the server
{#link Response#disconnected} - A user disconnected from the server
{#link Response#names} - A listing of names in a channel
-
Method Summary
Modifier and TypeMethodDescriptionint
static Response
AResponse
for the case when a user first connects to the server and should be informed of their new nicknamestatic Response
disconnected
(Integer recipientId, String senderNickname) AResponse
for the case when a user disconnects from the server and other clients should be informed of this fact.boolean
static Response
Constructs an errorResponse
for the case where a client'sCommand
is invalid, and the client should be informed.getText()
int
hashCode()
static Response
Generate aNAMES
response that informs a client of the users that are present in a channel.static Response
names
(Integer userId, String userNickname, String channelName, SortedSet<String> channelUsers, String channelOwner) Generate aNAMES
response that informs a client of the users that are present in a channel.static Response
Response indicating no error has occurred when processing the specified command.toString()
-
Method Details
-
getRecipientId
- Returns:
- the recipient's userId
-
getText
- Returns:
- the text of the response
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Response>
-
toString
-
equals
-
hashCode
public int hashCode() -
connected
AResponse
for the case when a user first connects to the server and should be informed of their new nickname- Parameters:
userId
- for the newly connected clientuserNickname
- for the client, generated by the server- Returns:
- CONNECT response
-
disconnected
AResponse
for the case when a user disconnects from the server and other clients should be informed of this fact.- Parameters:
recipientId
- the userId of the recipientsenderNickname
- the nickname of the disconnected user- Returns:
- QUIT response
-
okay
Response indicating no error has occurred when processing the specified command. This response merely echos the command preceded by the nickname of the user that issue it.- Parameters:
recipientId
- the userId of the recipientsenderNickname
- the nickname of user who sent the commandcommand
-Command
to be echoed- Returns:
- OKAY response
-
error
Constructs an errorResponse
for the case where a client'sCommand
is invalid, and the client should be informed. The response includes a code describing the error.- Parameters:
command
- The command that caused the errorerrorCode
- TheErrorCode
that the command caused- Returns:
- ERROR response
-
names
public static Response names(Integer userId, String userNickname, String channelName, SortedSet<String> channelUsers, String channelOwner) Generate aNAMES
response that informs a client of the users that are present in a channel.- Parameters:
userId
- that requested the list of namesuserNickname
- that requested the list of nameschannelName
- name of the channelchannelUsers
- nicknames of the users in the channelchannelOwner
- nickname of the channel owner- Returns:
- NAMES response
- Throws:
IllegalArgumentException
- if the channelOwner is not present in channelUsers
-
names
public static Response names(Integer userId, String userNickname, String channelName, String payload) Generate aNAMES
response that informs a client of the users that are present in a channel. This method should only be used for testing purposes. Do not hard-code the payload string from within ServerModel.- Parameters:
userId
- that requested the list of namesuserNickname
- nickname for user that issued requestchannelName
- name of the channelpayload
- string containing all nicknames in channel, in alphabetical order, with channel owner marked with '@' sign.- Returns:
- NAMES response
-