com.geotab.model.enumeration.FaultLampState Maven / Gradle / Ivy
/*
*
* 2020 Copyright (C) Geotab Inc. All rights reserved.
*/
package com.geotab.model.enumeration;
import com.fasterxml.jackson.annotation.JsonValue;
import com.geotab.model.entity.faultdata.FaultData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
* Represents the lamp status of a J1939 fault, see {@link FaultData}.
*/
@Slf4j
public enum FaultLampState {
/**
* Fault lamp is off, no active fault state.
*/
NONE("None"),
/**
* Malfunction lamp is active.
*/
MALFUNCTION("Malfunction"),
/**
* Amber warning lamp is active.
*/
WARNING("Warning"),
/**
* Red stop lamp is active.
*/
STOP("Stop"),
/**
* Protect lamp is active.
*/
PROTECT("Protect");
private String name;
FaultLampState(String name) {
this.name = name;
}
@JsonValue
public String getName() {
return name;
}
public static FaultLampState findOrDefault(String name) {
if (StringUtils.isEmpty(name)) {
log.warn("Empty value is not recognized for {} enum; returning default {}",
FaultLampState.class.getSimpleName(), FaultLampState.NONE);
return NONE;
}
for (FaultLampState faultLampState : values()) {
if (faultLampState.getName().equalsIgnoreCase(name.trim())) {
return faultLampState;
}
}
log.warn("{} is not recognized for {} enum; returning default {}",
name, FaultLampState.class.getSimpleName(), FaultLampState.NONE);
return NONE;
}
}