/** * Copyright (c) 2012 Perforce Software. All rights reserved. */ package com.perforce.p4java_ext; import com.perforce.p4java.exception.MessageSeverityCode; import com.perforce.p4java.impl.mapbased.rpc.msg.RpcMessage; public class ErrorId { private final int sub; private final int gen; private final int sev; private final int cod; private final int arg; private final String format; /** * server error code format is mostly returned by p4java. * <p/> * Bit format is: * <p/> * <pre> * | severity(4) | arg COUNT(4) | generic code(8) | subsystem(6) | error code(10) | * </pre> */ public ErrorId(String code) { sev = RpcMessage.getSeverity(code); // 4 bits arg = (Integer.valueOf(code) >> 24) & 0x0f; // 4 bits gen = RpcMessage.getGeneric(code); // 8 bits sub = RpcMessage.getSubsystem(code); // 6 bits cod = Integer.valueOf(code) & 0x3ff; // 10bits format = null; } public ErrorId(ErrorId e, String fmt) { this.sub = e.sub; this.arg = e.arg; this.cod = e.cod; this.sev = e.sev; this.gen = e.gen; format = fmt; } public ErrorId(int sub, int cod, int sev, int gen, int arg, String fmt) { this.sub = sub; this.arg = arg; this.cod = cod; this.sev = sev; this.gen = gen; format = fmt; } public int getSubsystem() { return sub; } public int getSeverity() { return sev; } public int getGeneric() { return gen; } public int getCode() { return cod; } public int getArg() { return arg; } public String getFormat() { return format; } @Override public String toString() { return String.valueOf(hashCode()); } public boolean match(String code) { if (code == null || !code.trim().matches("\\d+")) return false; return this.equals(new ErrorId(code.trim())); } @Override public boolean equals(Object obj) { if (obj instanceof ErrorId) { // only compare the subsystem/code/generics, the rest can change // from server version to server version ErrorId id = (ErrorId) obj; return sev != MessageSeverityCode.E_EMPTY && getSubsystem() == id.getSubsystem() && getCode() == id.getCode() && getGeneric() == id.getGeneric(); } return false; } @Override public int hashCode() { return (sev << 28) | (arg << 24) | (gen << 16) | (sub << 10) | cod; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9086 | tjuricek |
0.1.0 Initial release of p4java_ext Mostly just contains enough of the P4 API to build the test data initializer. About 4 commands have minimal testing, so it works. Kind of. |
||
#1 | 9085 | tjuricek | First import of the project, before package refactoring. |