io.github.ericdriggs.reportcard.model.FaultContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reportcard-model Show documentation
Show all versions of reportcard-model Show documentation
test report metrics and trend analysis reporting :: reportcard-model
package io.github.ericdriggs.reportcard.model;
import java.util.HashMap;
import java.util.Map;
public enum FaultContext {
ERROR((byte) 1, "error", FaultContextType.ERROR),
FAILURE((byte) 2, "failure", FaultContextType.FAILURE),
FLAKY_ERROR((byte)3, "flakyError", FaultContextType.ERROR),
FLAKY_FAILURE((byte)4, "flakyFailure", FaultContextType.FAILURE),
RERUN_ERROR((byte)5, "rerunError", FaultContextType.ERROR),
RERUN_FAILURE((byte)6, "rerunFailure", FaultContextType.FAILURE),
;
FaultContext(byte faultContextId, String xmlFaultContextName, FaultContextType faultContextType) {
this.faultContextId = faultContextId;
this.xmlFaultContextName = xmlFaultContextName;
this.faultContextType = faultContextType;
}
private final byte faultContextId;
private final String xmlFaultContextName;
private final FaultContextType faultContextType;
public byte getFaultContextId() {
return faultContextId;
}
public String getXmlFaultContextName() {
return xmlFaultContextName;
}
public FaultContextType getFaultContextType() {
return faultContextType;
}
private static final Map idContextMap = new HashMap<>();
private static final Map xmlNameContextMap = new HashMap<>();
private static void initMaps() {
if (idContextMap.isEmpty()) {
synchronized ("testContextMap") {
for (FaultContext faultContext : FaultContext.values()) {
idContextMap.put(faultContext.getFaultContextId(), faultContext);
}
}
}
if (xmlNameContextMap.isEmpty()) {
synchronized ("nameContextMap") {
for (FaultContext faultContext : FaultContext.values()) {
xmlNameContextMap.put(faultContext.getXmlFaultContextName(), faultContext);
}
}
}
}
public static FaultContext fromFaultContextId(Byte faultContextId) {
if (faultContextId == null) {
return null;
}
initMaps();
FaultContext faultContext = idContextMap.get(faultContextId);
if (faultContext == null) {
throw new IllegalArgumentException("faultContextId not found: " + faultContextId);
}
return faultContext;
}
public static FaultContext fromXmlFaultContextName(String xmlFaultContextName) {
if (xmlFaultContextName == null) {
return null;
}
initMaps();
FaultContext faultContext = xmlNameContextMap.get(xmlFaultContextName);
if (faultContext == null) {
throw new IllegalArgumentException("xmlFaultContextName not found: " + xmlFaultContextName);
}
return faultContext;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy