All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.geotab.model.enumeration.DtcClass Maven / Gradle / Ivy

package com.geotab.model.enumeration;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * Represents a severity/class code from the engine system of the specific {@link
 * com.geotab.model.entity.device.Device}.
 */
@Slf4j
public enum DtcClass {

  /**
   * DTCClass 0 is unclassified.
   */
  UNCLASSIFIED("Unclassified", 0),

  /**
   * DTCClass 1 matches the GTR module B Class A definition.
   */
  A("A", 1),

  /**
   * DTCClass 2 matches the GTR module B Class B1 definition.
   */
  B1("B1", 2),

  /**
   * DTCClass 3 matches the GTR module B Class B2 definition.
   */
  B2("B2", 3),

  /**
   * DTCClass 4 matches the GTR module B Class C Definition.
   */
  C("C", 4);

  private String name;
  private int code;

  DtcClass(String name, int code) {
    this.name = name;
    this.code = code;
  }

  public int getCode() {
    return code;
  }

  @JsonValue
  public String getName() {
    return name;
  }

  public static DtcClass findOrDefault(String name) {
    if (StringUtils.isEmpty(name)) {
      log.warn("Empty value is not recognized for {} enum; returning default {}",
          DtcClass.class.getSimpleName(), DtcClass.UNCLASSIFIED);
      return UNCLASSIFIED;
    }

    for (DtcClass dtcClass : values()) {
      if (dtcClass.getName().equalsIgnoreCase(name.trim())) {
        return dtcClass;
      }
    }

    log.warn("{} is not recognized for {} enum; returning default {}",
        name, DtcClass.class.getSimpleName(), DtcClass.UNCLASSIFIED);
    return UNCLASSIFIED;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy