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

xyz.luan.console.parser.util.ClassMap Maven / Gradle / Ivy

Go to download

Java library to easily parse console input directly into controller classes with elegance.

There is a newer version: 1.0.4
Show newest version
package xyz.luan.console.parser.util;

import java.util.Map;

public class ClassMap {

	public static  T getFromClassMap(Map, T> map, Class originalClass) {
		if (originalClass.isPrimitive()) {
			throw new RuntimeException("Primitives not supported as actions and handlers arguments!");
		}
        Class clazz = originalClass;
        T t = map.get(clazz);
        while (t == null) {
            t = map.get(clazz = clazz.getSuperclass());
            if (clazz.equals(Object.class)) {
                break;
            }
        }
        if (t == null) {
            Class[] its = originalClass.getClass().getInterfaces();
            for (Class it : its) {
                t = map.get(it);
                if (t != null) {
                    break;
                }
            }
        }
        return t;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy