Java 枚举的使用
geekymv 发表于:2022-10-31 18:46:19 阅读数:2427
public enum DownSampling {
/**
* None downsampling is for un-time-series data.
*/
None(0, ""),
/**
* Second downsampling is not for metrics, but for record, profile and top n. Those are details but don't do
* aggregation, and still merge into day level in the persistence.
*/
Second(1, "second"),
Minute(2, "minute"),
Hour(3, "hour"),
Day(4, "day");
private final int value;
private final String name;
DownSampling(int value, String name) {
this.value = value;
this.name = name;
}
public int getValue() {
return value;
}
public String getName() {
return name;
}
}
public class DownSamplingConfigService implements Service {
private boolean shouldToHour = false;
private boolean shouldToDay = false;
public DownSamplingConfigService(List<String> downsampling) {
downsampling.forEach(value -> {
if (DownSampling.Hour.getName().toLowerCase().equals(value.toLowerCase())) {
shouldToHour = true;
} else if (DownSampling.Day.getName().toLowerCase().equals(value.toLowerCase())) {
shouldToDay = true;
}
});
}
public boolean shouldToHour() {
return shouldToHour;
}
public boolean shouldToDay() {
return shouldToDay;
}
}