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

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

/**
 * This enumerated type allows designating groups of devices to use different speed limits.
 */
@Slf4j
public enum SpeedLimitCategory {

  /**
   * Use the default speed limit.
   */
  NORMAL("Normal"),

  /**
   * Use the truck speed limit.
   */
  TRUCK("Truck"),

  /**
   * Unknown speed limit.
   */
  UNSPECIFIED("Unspecified");

  private String name;

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


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

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

    SpeedLimitCategory deviceType = findByName(name);
    if (deviceType != null) {
      return deviceType;
    }

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

  public static SpeedLimitCategory findByName(String name) {
    if (StringUtils.isEmpty(name)) {
      return null;
    }

    for (SpeedLimitCategory speedLimitCategory : values()) {
      if (speedLimitCategory.getName().equalsIgnoreCase(name.trim())) {
        return speedLimitCategory;
      }
    }

    return null;
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy