mirror of https://github.com/apache/jclouds.git
Prefer ImmutableMap for static ErrorCode map
Also mark member as final and fix line wrapping.
This commit is contained in:
parent
19390ea87d
commit
b0cd47befb
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.domain;
|
package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the error codes in the Virtual Box Java API into enum values.
|
* Maps the error codes in the Virtual Box Java API into enum values.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
@ -47,25 +48,41 @@ import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
||||||
*/
|
*/
|
||||||
public enum ErrorCode {
|
public enum ErrorCode {
|
||||||
|
|
||||||
VBOX_E_OBJECT_NOT_FOUND(2159738881L), VBOX_E_INVALID_VM_STATE(2159738882L), VBOX_E_VM_ERROR(2159738883L), VBOX_E_FILE_ERROR(
|
VBOX_E_OBJECT_NOT_FOUND(2159738881L),
|
||||||
2159738884L), VBOX_E_IPRT_ERROR(2159738885L), VBOX_E_PDM_ERROR(2159738886L), VBOX_E_INVALID_OBJECT_STATE(
|
VBOX_E_INVALID_VM_STATE(2159738882L),
|
||||||
2159738887L), VBOX_E_HOST_ERROR(2159738888L), VBOX_E_NOT_SUPPORTED(2159738889L), VBOX_E_XML_ERROR(2159738890L), VBOX_E_INVALID_SESSION_STATE(
|
VBOX_E_VM_ERROR(2159738883L),
|
||||||
2159738891L), VBOX_E_OBJECT_IN_USE(2159738892L), VBOX_E_ACCESSDENIED(2147942405L), VBOX_E_POINTER(2147500035L), VBOX_E_FAIL(
|
VBOX_E_FILE_ERROR(2159738884L),
|
||||||
2147500037L), VBOX_E_NOTIMPL(2147500033L), VBOX_E_OUTOFMEMORY(2147942414L), VBOX_E_INVALIDARG(2147942487L), VBOX_E_UNEXPECTED(
|
VBOX_E_IPRT_ERROR(2159738885L),
|
||||||
2147549183L), VBOX_E_UNKNOWN_ERROR_CODE(-1L), VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
|
VBOX_E_PDM_ERROR(2159738886L),
|
||||||
|
VBOX_E_INVALID_OBJECT_STATE(2159738887L),
|
||||||
|
VBOX_E_HOST_ERROR(2159738888L),
|
||||||
|
VBOX_E_NOT_SUPPORTED(2159738889L),
|
||||||
|
VBOX_E_XML_ERROR(2159738890L),
|
||||||
|
VBOX_E_INVALID_SESSION_STATE(2159738891L),
|
||||||
|
VBOX_E_OBJECT_IN_USE(2159738892L),
|
||||||
|
VBOX_E_ACCESSDENIED(2147942405L),
|
||||||
|
VBOX_E_POINTER(2147500035L),
|
||||||
|
VBOX_E_FAIL(2147500037L),
|
||||||
|
VBOX_E_NOTIMPL(2147500033L),
|
||||||
|
VBOX_E_OUTOFMEMORY(2147942414L),
|
||||||
|
VBOX_E_INVALIDARG(2147942487L),
|
||||||
|
VBOX_E_UNEXPECTED(2147549183L),
|
||||||
|
VBOX_E_UNKNOWN_ERROR_CODE(-1L),
|
||||||
|
VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
|
||||||
|
|
||||||
private long code;
|
private final long code;
|
||||||
|
|
||||||
ErrorCode(long code) {
|
ErrorCode(long code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Long, ErrorCode> table = new HashMap<Long, ErrorCode>();
|
private final static Map<Long, ErrorCode> TABLE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
ImmutableMap.Builder<Long, ErrorCode> builder = ImmutableMap.builder();
|
||||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||||
table.put(errorCode.code, errorCode);
|
builder.put(errorCode.code, errorCode);
|
||||||
}
|
}
|
||||||
|
TABLE = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +97,7 @@ public enum ErrorCode {
|
||||||
if (backend instanceof RuntimeFaultMsg) {
|
if (backend instanceof RuntimeFaultMsg) {
|
||||||
final RuntimeFaultMsg faultCode = (RuntimeFaultMsg) backend;
|
final RuntimeFaultMsg faultCode = (RuntimeFaultMsg) backend;
|
||||||
final int resultCode = faultCode.getFaultInfo().getResultCode();
|
final int resultCode = faultCode.getFaultInfo().getResultCode();
|
||||||
final ErrorCode errorCode = table.get(unsignedIntToLong(resultCode));
|
final ErrorCode errorCode = TABLE.get(unsignedIntToLong(resultCode));
|
||||||
if (errorCode != null) {
|
if (errorCode != null) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue