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

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

/*
 *
 * 2020 Copyright (C) Geotab Inc. All rights reserved.
 */

package com.geotab.model.enumeration;

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

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

  /**
   * None, fault not active.
   */
  NONE("None"),

  /**
   * Pending fault code.
   */
  PENDING("Pending"),

  /**
   * Pending fault code.
   */
  ACTIVE("Active");

  private String name;

  FaultState(String name) {
    this.name = name;
  }

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

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

    for (FaultState faultState : values()) {
      if (faultState.getName().equalsIgnoreCase(name.trim())) {
        return faultState;
      }
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy