io.github.avivcarmis.confEager.properties.ConfEagerPropertyEnum Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of conf-eager Show documentation
Show all versions of conf-eager Show documentation
Super simplistic and dynamic eager-initialization configuration library for Java.
The newest version!
package io.github.avivcarmis.confEager.properties;
import io.github.avivcarmis.confEager.ConfEager;
import io.github.avivcarmis.confEager.ConfEagerProperty;
/**
* Out of the box {@link io.github.avivcarmis.confEager.ConfEagerProperty}
* that maps {@link Enum} values.
*/
public class ConfEagerPropertyEnum> extends ConfEagerProperty {
private final Class _tClass;
private final boolean _caseSensitive;
public ConfEagerPropertyEnum(Class tClass, boolean caseSensitive, ConfEager.DefaultValue defaultValue, ConfEager.PropertyName propertyName) {
super(defaultValue, propertyName);
_tClass = tClass;
_caseSensitive = caseSensitive;
}
public ConfEagerPropertyEnum(Class tClass, boolean caseSensitive, ConfEager.PropertyName propertyName, ConfEager.DefaultValue defaultValue) {
super(propertyName, defaultValue);
_tClass = tClass;
_caseSensitive = caseSensitive;
}
public ConfEagerPropertyEnum(Class tClass, boolean caseSensitive, ConfEager.PropertyName propertyName) {
super(propertyName);
_tClass = tClass;
_caseSensitive = caseSensitive;
}
public ConfEagerPropertyEnum(Class tClass, boolean caseSensitive, ConfEager.DefaultValue defaultValue) {
super(defaultValue);
_tClass = tClass;
_caseSensitive = caseSensitive;
}
public ConfEagerPropertyEnum(Class tClass, boolean caseSensitive) {
_tClass = tClass;
_caseSensitive = caseSensitive;
}
@Override
protected T map(String value) {
if (_caseSensitive) {
return Enum.valueOf(_tClass, value);
}
for (T instance : _tClass.getEnumConstants()) {
if (instance.name().equalsIgnoreCase(value)) {
return instance;
}
}
throw new IllegalArgumentException("enum class " + _tClass.getName() + " has no value " + value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy