Package org.astrogrid.samp
Class Response
java.lang.Object
java.util.AbstractMap
org.astrogrid.samp.SampMap
org.astrogrid.samp.Response
- All Implemented Interfaces:
Map
Represents an encoded SAMP response.
- Since:
- 14 Jul 2008
- Author:
- Mark Taylor
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey for error map.static final StringSTATUS_KEYvalue indicating failure.static final StringSTATUS_KEYvalue indicating success.static final StringKey for result map.static final StringKey for response status.static final StringSTATUS_KEYvalue indicating partial success. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ResponseasResponse(Map map) Returns a map as a Response object.voidcheck()Checks that this object is ready for use with the SAMP toolkit.static ResponsecreateErrorResponse(ErrInfo errinfo) Returns a new response which is an error.static ResponsecreateSuccessResponse(Map result) Returns a new response which is a success.Returns the error object.Returns the result map.Returns the status value.booleanisOK()Indicates whether the result was an unequivocal success.voidsetErrInfo(Map errInfo) Sets the error object.voidSets the result map.voidSets the status value.Methods inherited from class org.astrogrid.samp.SampMap
checkHasKeys, entrySet, getList, getMap, getString, getUrl, putMethods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
STATUS_KEY
- See Also:
-
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:
-
ERROR_KEY
Key for error map. Only present in case of failure (or warning).- See Also:
-
OK_STATUS
STATUS_KEYvalue indicating success.- See Also:
-
WARNING_STATUS
STATUS_KEYvalue indicating partial success.- See Also:
-
ERROR_STATUS
STATUS_KEYvalue indicating failure.- See Also:
-
-
Constructor Details
-
Response
public Response()Constructs an empty response. -
Response
Constructs a response based on an existing map.- Parameters:
map- map containing initial data for this object
-
Response
Constructs a response with given status, result and error.- Parameters:
status-STATUS_KEYvalueresult-RESULT_KEYvalueerrinfo-ERROR_KEYvalue
-
-
Method Details
-
setStatus
Sets the status value.- Parameters:
status-STATUS_KEYvalue
-
getStatus
Returns the status value.- Returns:
STATUS_KEYvalue
-
setResult
Sets the result map.- Parameters:
result-RESULT_KEYvalue
-
getResult
Returns the result map.- Returns:
RESULT_KEYvalue
-
setErrInfo
Sets the error object.- Parameters:
errInfo-ERROR_KEYvalue- See Also:
-
getErrInfo
Returns the error object.- Returns:
ERROR_KEYvalue as anErrInfo
-
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:SampMapChecks that this object is ready for use with the SAMP toolkit. As well as callingSampUtils.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 informativeDataExceptionwill be thrown. -
createSuccessResponse
Returns a new response which is a success.- Parameters:
result- key-value map representing results of successful call- Returns:
- new success response
-
createErrorResponse
Returns a new response which is an error.- Parameters:
errinfo- error information- Returns:
- new error response
-
asResponse
Returns a map as a Response object.- Parameters:
map- map- Returns:
- response
-