Package org.cis1200

Class Command

java.lang.Object
org.cis1200.Command
Direct Known Subclasses:
CreateCommand, InviteCommand, JoinCommand, KickCommand, LeaveCommand, MessageCommand, NicknameCommand

public abstract class Command extends Object
A Command represents a string sent from a client to the server, after parsing it into a more convenient form. Each concrete subclass of the Command abstract class corresponds to a possible command that can be issued by a client. You do not need to modify this file, but you should read through it to make sure that you understand the various commands that the server needs to process and the data fields that are included in each of these command objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Command(int senderId, String sender)
    Constructor; initializes the private fields of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compare two commands Returns true if two Commands are equal; that is, if they produce the same string representation.
    Get the nickname of the client who issued the Command.
    int
    Get the user ID of the client who issued the Command.
    abstract Broadcast
    Process the command and update the server model accordingly.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Command

      Command(int senderId, String sender)
      Constructor; initializes the private fields of the object.
      Parameters:
      senderId - server-assigned ID of the sender
      sender - current nickname in use by the sender
  • Method Details

    • getSenderId

      public int getSenderId()
      Get the user ID of the client who issued the Command.
      Returns:
      The user ID of the client who issued this command
    • getSender

      public String getSender()
      Get the nickname of the client who issued the Command.
      Returns:
      The nickname of the client who issued this command
    • updateServerModel

      public abstract Broadcast updateServerModel(ServerModel model)
      Process the command and update the server model accordingly.
      Parameters:
      model - An instance of the ServerModel class which represents the current state of the server.
      Returns:
      A Broadcast object, informing clients about changes resulting from the command.
    • equals

      public boolean equals(Object o)
      Compare two commands Returns true if two Commands are equal; that is, if they produce the same string representation. Note that all subclasses of Command must override their toString method appropriately for this definition to make sense. (We have done this for you below.)
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare with this for equality
      Returns:
      true iff both objects are non-null and equal to each other