com.geotab.model.enumeration.ValidLoggingPeriod Maven / Gradle / Ivy
package com.geotab.model.enumeration;
/*
*
* 2020 Copyright (C) Geotab Inc. All rights reserved.
*/
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
/**
* The interval in which a Engine.Diagnostic reading is monitored, may be logged and the slope can
* be drawn between values and interpolated according to the slope of the line.
*/
@Slf4j
public enum ValidLoggingPeriod {
/**
* No period in which it is valid to interpolate.
*/
NONE("None", 0),
/**
* May be logged within the active state of the device.
*/
ACTIVE("Active", 1),
/**
* May be logged within the power state of the device.
*/
POWER("Power", 2);
private String name;
private int code;
ValidLoggingPeriod(String name, int code) {
this.name = name;
this.code = code;
}
public int getCode() {
return code;
}
@JsonValue
public String getName() {
return name;
}
public static ValidLoggingPeriod findOrDefault(String name) {
if (StringUtils.isEmpty(name)) {
log.warn("Empty value is not recognized for {} enum; returning default {}",
ValidLoggingPeriod.class.getSimpleName(), NONE);
return NONE;
}
for (ValidLoggingPeriod validLoggingPeriod : values()) {
if (validLoggingPeriod.getName().equalsIgnoreCase(name.trim())) {
return validLoggingPeriod;
}
}
log.warn("{} is not recognized for {} enum; returning default {}",
name, ValidLoggingPeriod.class.getSimpleName(), NONE);
return NONE;
}
}