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

com.g2forge.alexandria.java.enums.HEnum Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
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());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy