Class Response

  • All Implemented Interfaces:
    java.util.Map

    public class Response
    extends SampMap
    Represents an encoded SAMP response.
    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>
    • Constructor Summary

      Constructors 
      Constructor Description
      Response()
      Constructs an empty response.
      Response​(java.lang.String status, java.util.Map result, ErrInfo errinfo)
      Constructs a response with given status, result and error.
      Response​(java.util.Map map)
      Constructs a response based on an existing map.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Response asResponse​(java.util.Map map)
      Returns a map as a Response object.
      void check()
      Checks that this object is ready for use with the SAMP toolkit.
      static Response createErrorResponse​(ErrInfo errinfo)
      Returns a new response which is an error.
      static Response createSuccessResponse​(java.util.Map result)
      Returns a new response which is a success.
      ErrInfo getErrInfo()
      Returns the error object.
      java.util.Map getResult()
      Returns the result map.
      java.lang.String getStatus()
      Returns the status value.
      boolean isOK()
      Indicates whether the result was an unequivocal success.
      void setErrInfo​(java.util.Map errInfo)
      Sets the error object.
      void setResult​(java.util.Map result)
      Sets the result map.
      void setStatus​(java.lang.String status)
      Sets the status value.
      • 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

      • RESULT_KEY

        public static final java.lang.String RESULT_KEY
        Key for result map. This is a map of key-value pairs with semantics defined by the original message's MType. Only present in case of success (or warning).
        See Also:
        Constant Field Values
      • ERROR_KEY

        public static final java.lang.String ERROR_KEY
        Key for error map. Only present in case of failure (or warning).
        See Also:
        Constant Field Values
    • Constructor Detail

      • Response

        public Response()
        Constructs an empty response.
      • Response

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

        public Response​(java.lang.String status,
                        java.util.Map result,
                        ErrInfo errinfo)
        Constructs a response with given status, result and error.
        Parameters:
        status - STATUS_KEY value
        result - RESULT_KEY value
        errinfo - ERROR_KEY value
    • Method Detail

      • setStatus

        public void setStatus​(java.lang.String status)
        Sets the status value.
        Parameters:
        status - STATUS_KEY value
      • getStatus

        public java.lang.String getStatus()
        Returns the status value.
        Returns:
        STATUS_KEY value
      • setResult

        public void setResult​(java.util.Map result)
        Sets the result map.
        Parameters:
        result - RESULT_KEY value
      • getResult

        public java.util.Map getResult()
        Returns the result map.
        Returns:
        RESULT_KEY value
      • setErrInfo

        public void setErrInfo​(java.util.Map errInfo)
        Sets the error object.
        Parameters:
        errInfo - ERROR_KEY value
        See Also:
        ErrInfo
      • getErrInfo

        public ErrInfo getErrInfo()
        Returns the error object.
        Returns:
        ERROR_KEY value as an ErrInfo
      • isOK

        public boolean isOK()
        Indicates whether the result was an unequivocal success.
        Returns:
        true iff getStatus()==OK_STATUS
      • 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
      • createSuccessResponse

        public static Response createSuccessResponse​(java.util.Map result)
        Returns a new response which is a success.
        Parameters:
        result - key-value map representing results of successful call
        Returns:
        new success response
      • createErrorResponse

        public static Response createErrorResponse​(ErrInfo errinfo)
        Returns a new response which is an error.
        Parameters:
        errinfo - error information
        Returns:
        new error response
      • asResponse

        public static Response asResponse​(java.util.Map map)
        Returns a map as a Response object.
        Parameters:
        map - map
        Returns:
        response