From 2bb5260144697316e5c93cfca9812511ee0b3354 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 5 Jun 2016 16:01:08 -0700 Subject: [PATCH] GUACAMOLE-44: Provide for direct translation of status codes into GuacamoleStatus values. --- .../guacamole/protocol/GuacamoleStatus.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleStatus.java b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleStatus.java index 4dbae64bc..a5e84c689 100644 --- a/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleStatus.java +++ b/guacamole-common/src/main/java/org/apache/guacamole/protocol/GuacamoleStatus.java @@ -166,5 +166,31 @@ public enum GuacamoleStatus { public int getGuacamoleStatusCode() { return guac_code; } - + + /** + * Returns the GuacamoleStatus corresponding to the given Guacamole + * protocol status code. If no such GuacamoleStatus is defined, null is + * returned. + * + * @param code + * The Guacamole protocol status code to translate into a + * GuacamoleStatus. + * + * @return + * The GuacamoleStatus corresponding to the given Guacamole protocol + * status code, or null if no such GuacamoleStatus is defined. + */ + public static GuacamoleStatus fromGuacamoleStatusCode(int code) { + + // Search for a GuacamoleStatus having the given status code + for (GuacamoleStatus status : values()) { + if (status.getGuacamoleStatusCode() == code) + return status; + } + + // No such status found + return null; + + } + }