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

com.infilos.spring.utils.CodeBasedEnum Maven / Gradle / Ivy

package com.infilos.spring.utils;

import com.fasterxml.jackson.annotation.JsonValue;

public interface CodeBasedEnum> {

    @JsonValue
    int getCode();

    static , E extends Enum> T fromCode(Class type, int code) {
        for (T t : type.getEnumConstants()) {
            if (t.getCode() == code) {
                return t;
            }
        }

        throw new IllegalArgumentException(String.format("%s cannot match the code: %s", type.getSimpleName(), code));
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy