From a6ed3b25147e256c84f0e143eadf406f330c88ea Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 10 Mar 2014 21:53:33 +0100 Subject: [PATCH] Use static block in XMPPError The Condition to ErrorSpecification map is now build within a static block. --- .../jivesoftware/smack/packet/XMPPError.java | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index 018da0ed6..1c05526fc 100644 --- a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -14,10 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.jivesoftware.smack.packet; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Represents a XMPP error sub-packet. Typically, a server responds to a request that has @@ -351,10 +354,12 @@ public class XMPPError { * A class to represent the error specification used to infer common usage. */ private static class ErrorSpecification { - private int code; - private Type type; - private Condition condition; - private static Map instances = errorSpecifications(); + private static Map instances = new HashMap(); + + private final int code; + private final Type type; + @SuppressWarnings("unused") + private final Condition condition; private ErrorSpecification(Condition condition, Type type, int code) { this.code = code; @@ -362,8 +367,7 @@ public class XMPPError { this.condition = condition; } - private static Map errorSpecifications() { - Map instances = new HashMap(22); + static { instances.put(Condition.interna_server_error, new ErrorSpecification( Condition.interna_server_error, Type.WAIT, 500)); instances.put(Condition.forbidden, new ErrorSpecification(Condition.forbidden, @@ -412,23 +416,12 @@ public class XMPPError { Condition.unexpected_request, Type.WAIT, 400)); instances.put(Condition.request_timeout, new XMPPError.ErrorSpecification( Condition.request_timeout, Type.CANCEL, 408)); - - return instances; } protected static ErrorSpecification specFor(Condition condition) { return instances.get(condition); } - /** - * Returns the error condition. - * - * @return the error condition. - */ - protected Condition getCondition() { - return condition; - } - /** * Returns the error type. *