Class Message

  • All Implemented Interfaces:
    java.util.Map

    public class Message
    extends SampMap
    Represents an encoded SAMP Message.
    Since:
    14 Jul 2008
    Author:
    Mark Taylor
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] KNOWN_KEYS  
      static java.lang.String MTYPE_KEY
      Key for message MType.
      static java.lang.String PARAMS_KEY
      Key for map of parameters used by this message.
    • Constructor Summary

      Constructors 
      Constructor Description
      Message()
      Constructs an empty message.
      Message​(java.lang.String mtype)
      Constructs a message with a given MType.
      Message​(java.lang.String mtype, java.util.Map params)
      Constructs a message with a given MType and params map.
      Message​(java.util.Map map)
      Constructs a message based on an existing map.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Message addParam​(java.lang.String name, java.lang.Object value)
      Sets the value for a single entry in this message's samp.params map.
      static Message asMessage​(java.util.Map map)
      Returns a given map as a Message object.
      void check()
      Checks that this object is ready for use with the SAMP toolkit.
      java.lang.String getMType()
      Returns this message's MType.
      java.lang.Object getParam​(java.lang.String name)
      Returns the value of a single entry in this message's samp.params map.
      java.util.Map getParams()
      Returns this message's params map.
      java.lang.Object getRequiredParam​(java.lang.String name)
      Returns the value of a single entry in this message's samp.params map, throwing an exception if it is not present.
      void setParams​(java.util.Map params)
      Sets this message's params map.
      • Methods inherited from class java.util.AbstractMap

        clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • MTYPE_KEY

        public static final java.lang.String MTYPE_KEY
        Key for message MType.
        See Also:
        Constant Field Values
      • PARAMS_KEY

        public static final java.lang.String PARAMS_KEY
        Key for map of parameters used by this message.
        See Also:
        Constant Field Values
      • KNOWN_KEYS

        private static final java.lang.String[] KNOWN_KEYS
    • Constructor Detail

      • Message

        public Message()
        Constructs an empty message.
      • Message

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

        public Message​(java.lang.String mtype,
                       java.util.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​(java.lang.String mtype)
        Constructs a message with a given MType. The parameters map will be mutable.
        Parameters:
        mtype - value for MTYPE_KEY key
    • Method Detail

      • getMType

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

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

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

        public Message addParam​(java.lang.String name,
                                java.lang.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 java.lang.Object getParam​(java.lang.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 java.lang.Object getRequiredParam​(java.lang.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​(java.util.Map map)
        Returns a given map as a Message object.
        Parameters:
        map - map
        Returns:
        message