Package it.meucci.utils
Class Message
java.lang.Object
it.meucci.utils.Message
Messages that are exchanged between client and server.
They have a type, a recipient, and a sender.
Contain an optional field called "content", used for various purposes, depending on the type of message.
Has a static validate method that converts user input into a Message.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Message
createChangeNameCommand
(String newName) Creates a message to change namestatic Message
createMessage
(String to, String content) Creates a message of type MESSAGEgetArgs()
getFrom()
getType()
static String
Humanizes the message in order to be correctly displayed.toString()
-
Constructor Details
-
Message
Message Costructor- Parameters:
type
- The Message typeType
from
- The senderto
- The addresseeargs
- Arguments of the message. They follow a different syntax depending on the type of the message
-
-
Method Details
-
createMessage
Creates a message of type MESSAGE- Parameters:
to
- the addresseecontent
- the content to be sent- Returns:
- the composed message.
-
getType
-
getFrom
-
getArgs
-
createChangeNameCommand
Creates a message to change name- Parameters:
newName
- the new name the user wants to use- Returns:
- the composed message
-
toString
-
humanize
Humanizes the message in order to be correctly displayed. Like handling methods, this is a wrapper to call humanize just once and avoid code duplication. toString() could have be used, but we didn't want to mess with it since we wanted to reserve it for debug purposes.- Parameters:
m
- The message to be humanized- Returns:
- A string ready to be printed
-