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

com.geotab.model.enumeration.FaultResetMode 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;

/**
 * Specify whether the fault resets automatically or manually.
 */
@Slf4j
public enum FaultResetMode {

  /**
   * The engine FaultData ExceptionEvent for this kind of Diagnostic can contain a number of
   * sequential {@link FaultData} instances. These instances will continue to grow until the fault
   * condition ends.
   */
  NONE("None", 0),

  /**
   * The engine FaultData ExceptionEvent for this kind of Diagnostic will always contain single
   * FaultData instance.
   */
  AUTO_RESET("AutoReset", 1);

  private String name;
  private int code;

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

  public int getCode() {
    return code;
  }

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

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

    for (FaultResetMode faultResetMode : values()) {
      if (faultResetMode.getName().equalsIgnoreCase(name.trim())) {
        return faultResetMode;
      }
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy