mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 23:42:06 +01:00
Use static block in XMPPError
The Condition to ErrorSpecification map is now build within a static block.
This commit is contained in:
parent
b8a5437b28
commit
a6ed3b2514
1 changed files with 12 additions and 19 deletions
|
@ -14,10 +14,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jivesoftware.smack.packet;
|
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
|
* 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.
|
* A class to represent the error specification used to infer common usage.
|
||||||
*/
|
*/
|
||||||
private static class ErrorSpecification {
|
private static class ErrorSpecification {
|
||||||
private int code;
|
private static Map<Condition, ErrorSpecification> instances = new HashMap<Condition, ErrorSpecification>();
|
||||||
private Type type;
|
|
||||||
private Condition condition;
|
private final int code;
|
||||||
private static Map<Condition, ErrorSpecification> instances = errorSpecifications();
|
private final Type type;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final Condition condition;
|
||||||
|
|
||||||
private ErrorSpecification(Condition condition, Type type, int code) {
|
private ErrorSpecification(Condition condition, Type type, int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
@ -362,8 +367,7 @@ public class XMPPError {
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Condition, ErrorSpecification> errorSpecifications() {
|
static {
|
||||||
Map<Condition, ErrorSpecification> instances = new HashMap<Condition, ErrorSpecification>(22);
|
|
||||||
instances.put(Condition.interna_server_error, new ErrorSpecification(
|
instances.put(Condition.interna_server_error, new ErrorSpecification(
|
||||||
Condition.interna_server_error, Type.WAIT, 500));
|
Condition.interna_server_error, Type.WAIT, 500));
|
||||||
instances.put(Condition.forbidden, new ErrorSpecification(Condition.forbidden,
|
instances.put(Condition.forbidden, new ErrorSpecification(Condition.forbidden,
|
||||||
|
@ -412,23 +416,12 @@ public class XMPPError {
|
||||||
Condition.unexpected_request, Type.WAIT, 400));
|
Condition.unexpected_request, Type.WAIT, 400));
|
||||||
instances.put(Condition.request_timeout, new XMPPError.ErrorSpecification(
|
instances.put(Condition.request_timeout, new XMPPError.ErrorSpecification(
|
||||||
Condition.request_timeout, Type.CANCEL, 408));
|
Condition.request_timeout, Type.CANCEL, 408));
|
||||||
|
|
||||||
return instances;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ErrorSpecification specFor(Condition condition) {
|
protected static ErrorSpecification specFor(Condition condition) {
|
||||||
return instances.get(condition);
|
return instances.get(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the error condition.
|
|
||||||
*
|
|
||||||
* @return the error condition.
|
|
||||||
*/
|
|
||||||
protected Condition getCondition() {
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the error type.
|
* Returns the error type.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue