com.g2forge.alexandria.java.enums.HEnum Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.enums;
import java.util.LinkedHashMap;
import java.util.Map;
import com.g2forge.alexandria.java.marker.Helpers;
import lombok.experimental.UtilityClass;
@Helpers
@UtilityClass
public class HEnum {
public static > E valueOfInsensitive(Class klass, String text) {
final Map map = new LinkedHashMap<>();
for (E value : klass.getEnumConstants()) {
if (map.put(value.toString().toLowerCase(), value) != null) throw new IllegalArgumentException("Cannot perform case insensitive matching on enum \"" + klass + "\" because the members are not unique without casing!");
}
return map.get(text.toLowerCase());
}
}