Package org.cis1200

Class Response

java.lang.Object
org.cis1200.Response
All Implemented Interfaces:
Comparable<Response>

public final class Response extends Object implements 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 Details

    • getRecipientId

      public Integer getRecipientId()
      Returns:
      the recipient's userId
    • getText

      public String getText()
      Returns:
      the text of the response
    • compareTo

      public int compareTo(Response o)
      Specified by:
      compareTo in interface Comparable<Response>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • connected

      public static Response connected(Integer userId, String userNickname)
      A Response 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 client
      userNickname - for the client, generated by the server
      Returns:
      CONNECT response
    • disconnected

      public static Response disconnected(Integer recipientId, String senderNickname)
      A Response 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 recipient
      senderNickname - the nickname of the disconnected user
      Returns:
      QUIT response
    • okay

      public static Response okay(Integer recipientId, String senderNickname, Command command)
      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 recipient
      senderNickname - the nickname of user who sent the command
      command - Command to be echoed
      Returns:
      OKAY response
    • error

      public static Response error(Command command, ErrorCode errorCode)
      Constructs an error Response for the case where a client's Command is invalid, and the client should be informed. The response includes a code describing the error.
      Parameters:
      command - The command that caused the error
      errorCode - The ErrorCode that the command caused
      Returns:
      ERROR response
    • names

      public static Response names(Integer userId, String userNickname, String channelName, SortedSet<String> channelUsers, String channelOwner)
      Generate a NAMES response that informs a client of the users that are present in a channel.
      Parameters:
      userId - that requested the list of names
      userNickname - that requested the list of names
      channelName - name of the channel
      channelUsers - nicknames of the users in the channel
      channelOwner - 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 a NAMES 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 names
      userNickname - nickname for user that issued request
      channelName - name of the channel
      payload - string containing all nicknames in channel, in alphabetical order, with channel owner marked with '@' sign.
      Returns:
      NAMES response