Package org.cis1200
Class Command
java.lang.Object
org.cis1200.Command
- Direct Known Subclasses:
CreateCommand
,InviteCommand
,JoinCommand
,KickCommand
,LeaveCommand
,MessageCommand
,NicknameCommand
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 -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compare two commands Returnstrue
if twoCommand
s are equal; that is, if they produce the same string representation.Get the nickname of the client who issued theCommand
.int
Get the user ID of the client who issued theCommand
.abstract Broadcast
updateServerModel
(ServerModel model) Process the command and update the server model accordingly.
-
Constructor Details
-
Command
Command(int senderId, String sender) Constructor; initializes the private fields of the object.- Parameters:
senderId
- server-assigned ID of the sendersender
- current nickname in use by the sender
-
-
Method Details
-
getSenderId
public int getSenderId()Get the user ID of the client who issued theCommand
.- Returns:
- The user ID of the client who issued this command
-
getSender
Get the nickname of the client who issued theCommand
.- Returns:
- The nickname of the client who issued this command
-
updateServerModel
Process the command and update the server model accordingly.- Parameters:
model
- An instance of theServerModel
class which represents the current state of the server.- Returns:
- A
Broadcast
object, informing clients about changes resulting from the command.
-
equals
Compare two commands Returnstrue
if twoCommand
s are equal; that is, if they produce the same string representation. Note that all subclasses ofCommand
must override theirtoString
method appropriately for this definition to make sense. (We have done this for you below.)
-