List of usage examples for java.lang Class isAssignableFrom
@HotSpotIntrinsicCandidate public native boolean isAssignableFrom(Class<?> cls);
From source file:Main.java
public static boolean isFrom(Class<?> parent, Class<?> subclass) { if (parent == subclass) { return true; }/*from w ww . j ava 2s.com*/ if (parent == null || subclass == null) { return false; } return parent.isAssignableFrom(subclass); }
From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java
public static void testOneWay(Class<? extends CollectionReader> aReader, Class<? extends AnalysisComponent> aWriter, String aExpectedFile, String aFile, Object... aExtraParams) throws Exception { Class<?> dkproReaderBase = Class.forName(RESOURCE_COLLECTION_READER_BASE); if (!dkproReaderBase.isAssignableFrom(aReader)) { throw new IllegalArgumentException( "Reader must be a subclass of [" + RESOURCE_COLLECTION_READER_BASE + "]"); }/*from www .j ava 2s .c om*/ Class<?> dkproWriterBase = Class.forName(JCAS_FILE_WRITER_IMPL_BASE); if (!dkproWriterBase.isAssignableFrom(aWriter)) { throw new IllegalArgumentException("writer must be a subclass of [" + JCAS_FILE_WRITER_IMPL_BASE + "]"); } // We assume that the writer is creating a file with the same extension as is provided as // the expected file String extension = FilenameUtils.getExtension(aExpectedFile); String name = FilenameUtils.getBaseName(aFile); testOneWay2(aReader, aWriter, aExpectedFile, name + "." + extension, aFile, aExtraParams); }
From source file:game.utils.Utils.java
public static boolean isImplementation(Class type, Class base) { return isConcrete(type) && base.isAssignableFrom(type); }
From source file:com.sonicle.webtop.core.app.ComponentsManager.java
private static boolean isAssignableTo(Class clazz, Class baseClass) { if (clazz == null) return false; return baseClass.isAssignableFrom(clazz); }
From source file:com.myee.tarot.core.exception.ExceptionHelper.java
public static <G extends Throwable, J extends RuntimeException> void processException(Class<G> refineType, Class<J> wrapType, String message, Throwable e) throws G { if (refineType.isAssignableFrom(e.getClass())) { throw (G) e; }//from www.j av a 2 s.c o m if (e.getCause() != null) { processException(refineType, wrapType, message, e.getCause()); } if (e instanceof UndeclaredThrowableException) { processException(refineType, wrapType, message, ((UndeclaredThrowableException) e).getUndeclaredThrowable()); } if (e instanceof InvocationTargetException) { processException(refineType, wrapType, message, ((InvocationTargetException) e).getTargetException()); } throw wrapException(e, wrapType, message); }
From source file:com.floreantpos.extension.ExtensionManager.java
public static FloreantPlugin getPlugin(Class pluginClass) { for (FloreantPlugin floreantPlugin : getInstance().plugins) { if (pluginClass.isAssignableFrom(floreantPlugin.getClass())) { return floreantPlugin; }//from www. j a v a 2 s. co m } return null; }
From source file:fr.inria.atlanmod.neoemf.core.impl.NeoEMFEObjectAdapterFactoryImpl.java
@SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType.isInstance(adaptableObject)) { return (T) adaptableObject; } else if (adapterType.isAssignableFrom(NeoEMFInternalEObject.class) && adaptableObject instanceof InternalEObject) { {//from w w w . j ava 2s. c om EObject adapter = adaptedObjects.get(adaptableObject); if (adapter != null) { if (adapterType.isAssignableFrom(adapter.getClass())) { return (T) adapter; } } } { // Compute the interfaces that the proxy has to implement // These are the current interfaces + NeoEMFEObject List<Class<?>> interfaces = new ArrayList<>(); interfaces.addAll(ClassUtils.getAllInterfaces(adaptableObject.getClass())); interfaces.add(NeoEMFInternalEObject.class); // Create the proxy Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(NeoEMFEObjectAdapterFactoryImpl.class.getClassLoader()); enhancer.setSuperclass(adaptableObject.getClass()); enhancer.setInterfaces(interfaces.toArray(new Class[] {})); enhancer.setCallback(new NeoEMFEObjectProxyHandlerImpl((InternalEObject) adaptableObject)); T adapter = (T) enhancer.create(); adaptedObjects.put((InternalEObject) adaptableObject, (NeoEMFInternalEObject) adapter); return adapter; } } return null; }
From source file:org.grails.datastore.mapping.reflect.ReflectionUtils.java
private static boolean isTypeInstanceOfPropertyType(Class<?> type, Class<?> propertyType) { return propertyType.isAssignableFrom(type) && !propertyType.equals(Object.class); }
From source file:com.github.erchu.beancp.MapperExecutorSelector.java
private static boolean canBeMapped(final Class objectClass, final Class supportedClass) { return classEqualsOrWrapper(objectClass, supportedClass) || supportedClass.isAssignableFrom(objectClass); }
From source file:fr.inria.atlanmod.neoemf.core.impl.NeoEObjectAdapterFactoryImpl.java
@SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptableObject, Class<T> adapterType) { if (adapterType.isInstance(adaptableObject)) { return (T) adaptableObject; } else if (adapterType.isAssignableFrom(InternalPersistentEObject.class) && adaptableObject instanceof InternalEObject) { {//w ww.j ava 2s .com EObject adapter = adaptedObjects.get(adaptableObject); if (adapter != null) { if (adapterType.isAssignableFrom(adapter.getClass())) { return (T) adapter; } } } { // Compute the interfaces that the proxy has to implement // These are the current interfaces + PersistentEObject List<Class<?>> interfaces = new ArrayList<>(); interfaces.addAll(ClassUtils.getAllInterfaces(adaptableObject.getClass())); interfaces.add(InternalPersistentEObject.class); // Create the proxy Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(adaptableObject.getClass().getClassLoader()); enhancer.setSuperclass(adaptableObject.getClass()); enhancer.setInterfaces(interfaces.toArray(new Class[] {})); enhancer.setCallback(new NeoEObjectProxyHandlerImpl((InternalEObject) adaptableObject)); T adapter = (T) enhancer.create(); adaptedObjects.put((InternalEObject) adaptableObject, (InternalPersistentEObject) adapter); return adapter; } } return null; }