Java 枚举的使用

geekymv 发表于:2022-10-31 18:46:19 阅读数:2028

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;
    }

}

Barbara Middleton
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porta eros lacus, nec ultricies elit blandit non. Suspendisse pellentesque mauris sit amet dolor blandit rutrum. Nunc in tempus turpis.
Like · Reply · 3 hrs

Sean Brown
Donec sollicitudin urna eget eros malesuada sagittis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam blandit nisl a nulla sagittis, a lobortis leo feugiat.
Like · Reply · 2 hrs

Vivamus quis semper metus, non tincidunt dolor. Vivamus in mi eu lorem cursus ullamcorper sit amet nec massa.
Morbi vitae diam et purus tincidunt porttitor vel vitae augue. Praesent malesuada metus sed pharetra euismod. Cras tellus odio, tincidunt iaculis diam non, porta aliquet tortor.

Kayli Eunice
Sed convallis scelerisque mauris, non pulvinar nunc mattis vel. Maecenas varius felis sit amet magna vestibulum euismod malesuada cursus libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus lacinia non nisl id feugiat.
Like · Reply · 2 hrs