Class Message

All Implemented Interfaces:
Map

public class Message extends SampMap
Represents an encoded SAMP Message.
Since:
14 Jul 2008
Author:
Mark Taylor
  • Field Details

  • Constructor Details

    • Message

      public Message()
      Constructs an empty message.
    • Message

      public Message(Map map)
      Constructs a message based on an existing map.
      Parameters:
      map - map containing initial data for this object
    • Message

      public Message(String mtype, Map params)
      Constructs a message with a given MType and params map.
      Parameters:
      mtype - value for MTYPE_KEY key
      params - value for PARAMS_KEY key
    • Message

      public Message(String mtype)
      Constructs a message with a given MType. The parameters map will be mutable.
      Parameters:
      mtype - value for MTYPE_KEY key
  • Method Details

    • getMType

      public String getMType()
      Returns this message's MType.
      Returns:
      value for MTYPE_KEY
    • setParams

      public void setParams(Map params)
      Sets this message's params map.
      Parameters:
      params - value for PARAMS_KEY
    • getParams

      public Map getParams()
      Returns this message's params map.
      Returns:
      value for PARAMS_KEY
    • addParam

      public Message addParam(String name, Object value)
      Sets the value for a single entry in this message's samp.params map.
      Parameters:
      name - param name
      value - param value
    • getParam

      public Object getParam(String name)
      Returns the value of a single entry in this message's samp.params map. Null is returned if the parameter does not appear.
      Parameters:
      name - param name
      Returns:
      param value, or null
    • getRequiredParam

      public Object getRequiredParam(String name)
      Returns the value of a single entry in this message's samp.params map, throwing an exception if it is not present.
      Parameters:
      name - param name
      Returns:
      param value
      Throws:
      DataException - if no parameter name is present
    • check

      public void check()
      Description copied from class: SampMap
      Checks that this object is ready for use with the SAMP toolkit. As well as calling SampUtils.checkMap(java.util.Map) (ensuring that all keys are Strings, and all values Strings, Lists or Maps), subclass-specific invariants may be checked. In the case that there's something wrong, an informative DataException will be thrown.
      Overrides:
      check in class SampMap
    • asMessage

      public static Message asMessage(Map map)
      Returns a given map as a Message object.
      Parameters:
      map - map
      Returns:
      message