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

com.github.brunothg.swing2.utils.ClassUtils Maven / Gradle / Ivy

package com.github.brunothg.swing2.utils;

import java.util.HashMap;
import java.util.Map;

public class ClassUtils {

	private static final Map, Class> wrapperMapping = new MapBuilder, Class>(
			new HashMap, Class>()).put(boolean.class, Boolean.class)
					.put(byte.class, Byte.class)
					.put(char.class, Character.class)
					.put(double.class, Double.class)
					.put(float.class, Float.class).put(int.class, Integer.class)
					.put(long.class, Long.class).put(short.class, Short.class)
					.put(void.class, Void.class).build();

	/**
	 * Test, if assignable could be assigned to
	 * container.
* *
	 * container = assignable;
	 * 
* * @param container * Class that should be assigned to assignable * @param assignable * Class to which container should be cast * @return true, if assignable could be assigned to * container */ public static boolean isAssignable(Class container, Class assignable) { return getWrappedClass(container) .isAssignableFrom(getWrappedClass(assignable)); } /** * Transform the class to its wrapper class if any exists. Else the class * itself is returned. * * @param c * Class from which to get the wrapper class * @return A non primitive class */ @SuppressWarnings("unchecked") private static Class getWrappedClass(Class c) { return (c.isPrimitive()) ? (Class) wrapperMapping.get(c) : c; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy