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

tech.kronicle.utils.EnumUtils Maven / Gradle / Ivy

Go to download

Kronicle utils library that contains utility classes for use by Kronicle and its plugins

There is a newer version: 0.1.331
Show newest version
package tech.kronicle.utils;

import tech.kronicle.common.CaseUtils;

import java.util.List;
import java.util.stream.Collectors;

import static java.util.Objects.isNull;
import static java.util.Objects.requireNonNull;

public final class EnumUtils {

    public static > List getEnumListFromJsonValues(Class enumType, List values) {
        requireNonNull(enumType, "enumType");
        if (isNull(values)) {
            return List.of();
        }
        return values.stream()
                .map(value -> getEnumFromJsonValue(enumType, value))
                .collect(Collectors.toList());
    }

    public static > T getEnumFromJsonValue(Class enumType, String value) {
        requireNonNull(enumType, "enumType");
        return Enum.valueOf(enumType, CaseUtils.toScreamingSnakeCase(value));
    }

    private EnumUtils() {
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy