Class Message

java.lang.Object
it.meucci.utils.Message

public class Message extends Object
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 Details

    • Message

      public Message(Type type, String from, String to, ArrayList<String> args)
      Message Costructor
      Parameters:
      type - The Message type Type
      from - The sender
      to - The addressee
      args - Arguments of the message. They follow a different syntax depending on the type of the message
  • Method Details

    • createMessage

      public static Message createMessage(String to, String content)
      Creates a message of type MESSAGE
      Parameters:
      to - the addressee
      content - the content to be sent
      Returns:
      the composed message.
    • getType

      public Type getType()
    • getFrom

      public String getFrom()
    • getArgs

      public ArrayList<String> getArgs()
    • createChangeNameCommand

      public static Message createChangeNameCommand(String newName)
      Creates a message to change name
      Parameters:
      newName - the new name the user wants to use
      Returns:
      the composed message
    • toString

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

      public static String humanize(Message m)
      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