public class ErrorParser {
public static void main(String[] args) {
int ret = encodeDepError(Constants.ELEM_POOL, ErrorCode.STATUS
| ErrorCode.LACK | ErrorCode.PROBED_FAILED);
String retString = decodeDepError(ret);
System.out.println(retString);
}
public static int encodeDepError(int type, int errorCode) {
return -(type << 16 | errorCode);
}
public static String decodeDepError(int error) {
int type;
int errorCode;
int positiveError = -error;
type = positiveError >> 16;
errorCode = positiveError & 0xFFFF;
System.out.println("type = " + type);
System.out.println("errorCode = " + errorCode);
return "";
}
}
interface ErrorCode {
public static final int DUP = 1 << 0;
public static final int STATUS = 1 << 1;
public static final int LACK = 1 << 2;
public static final int PROBED_FAILED = 1 << 3;
}
interface Constants {
public static final int ELEM_CLUSTER = 0;
public static final int ELEM_HOST = 1;
public static final int ELEM_MON = 2;
public static final int ELEM_DISK = 3;
public static final int ELEM_OSD = 4;
public static final int ELEM_MDS = 5;
public static final int ELEM_POOL = 6;
public static final int ELEM_ACCS = 7;
public static final int ELEM_NTYPES = 8;
}
输出为:
type =6
errorCode = 14