![JAR search and dependency download from the Maven repository](/logo.png)
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