Example usage for java.lang Class getInterfaces

List of usage examples for java.lang Class getInterfaces

Introduction

In this page you can find the example usage for java.lang Class getInterfaces.

Prototype

public Class<?>[] getInterfaces() 

Source Link

Document

Returns the interfaces directly implemented by the class or interface represented by this object.

Usage

From source file:com.freetmp.common.util.ClassUtils.java

public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
    Assert.notNull(clazz, "Class must not be null");
    if (clazz.isInterface() && isVisible(clazz, classLoader)) {
        return Collections.<Class<?>>singleton(clazz);
    }//w  w  w.  j  a  va2s.  com
    Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
    while (clazz != null) {
        Class<?>[] ifcs = clazz.getInterfaces();
        for (Class<?> ifc : ifcs) {
            interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
        }
        clazz = clazz.getSuperclass();
    }
    return interfaces;
}

From source file:com.kotcrab.vis.editor.module.editor.PluginLoaderModule.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private Consumer getClassRegistrarRecursively(PluginDescriptor descriptor, Class<?> entryPointClass,
        Class<?> clazz) {
    Consumer consumer = entryPointsRegistrars.get(clazz);
    if (consumer == null) {
        for (Class interfaceClass : clazz.getInterfaces()) {
            Consumer interfaceConsumer = entryPointsRegistrars.get(interfaceClass);
            if (interfaceConsumer != null)
                return interfaceConsumer;
        }//from ww w .j av  a  2  s .  c  om

        Class parent = clazz.getSuperclass();

        if (parent != null) {
            return getClassRegistrarRecursively(descriptor, entryPointClass, parent);
        } else {
            //default consumer when no registrar have been found
            return ignored -> Log.warn("Plugin '" + descriptor.folderName
                    + "' was successfully loaded but it's plugin entry point class '"
                    + entryPointClass.getSimpleName() + "' object wasn't recognized.");
        }
    }
    return consumer;
}

From source file:org.eclipse.emf.teneo.ERuntime.java

/**
 * Retains only the root parent class in a list, so if an entry in the list as a parent in the
 * same list then the child is deleted from the list
 *///from   ww w  .java 2s  .  c  om
private void cleanList(ArrayList<Class<?>> list) {
    final ArrayList<Class<?>> toRemove = new ArrayList<Class<?>>();
    for (Class<?> clazz : list) {
        if (clazz == null) {
            continue;
        }
        final Class<?>[] supers = clazz.getInterfaces();
        for (Class<?> element : supers) {
            if (list.contains(element)) {
                toRemove.add(clazz);
                break;
            }
        }
    }
    list.removeAll(toRemove);
}

From source file:org.eclipse.wb.internal.core.model.description.helpers.ComponentDescriptionHelper.java

/**
 * Sets icon for {@link ComponentDescription}.
 * //  w w  w  .  j a v  a  2s. com
 * @param context
 *          the {@link EditorState} to access environment.
 * @param componentDescription
 *          the {@link ComponentDescription} to set icon for.
 * @param currentClass
 *          the {@link Class} to check for icon.
 */
private static void setIcon(ILoadingContext context, ComponentDescription componentDescription,
        Class<?> currentClass) throws Exception {
    if (currentClass != null) {
        // check current Class
        if (componentDescription.getIcon() == null) {
            Image icon = DescriptionHelper.getIconImage(context, currentClass);
            if (icon != null) {
                componentDescription.setIcon(icon);
                {
                    String name = componentDescription.getComponentClass().getName();
                    ImageDisposer.add(componentDescription, name, icon);
                }
                return;
            }
        }
        // check interfaces
        for (Class<?> interfaceClass : currentClass.getInterfaces()) {
            if (componentDescription.getIcon() == null) {
                setIcon(context, componentDescription, interfaceClass);
            }
        }
        // check super Class
        if (componentDescription.getIcon() == null) {
            setIcon(context, componentDescription, currentClass.getSuperclass());
        }
    }
}

From source file:eionet.util.Util.java

/**
 * Checks if a class implements the interface given as second argument.
 *
 * @param c - class as an object./* w  ww .  ja  v  a2 s.co m*/
 * @param ifName - interface name as string.
 */
public static boolean implementsIF(Class c, String ifName) {

    boolean f = false;
    Class[] ifs = c.getInterfaces();
    for (int i = 0; ifs != null && i < ifs.length; i++) {
        Class ifClass = ifs[i];
        if (ifClass.getName().endsWith(ifName)) {
            return true;
        }
    }

    return f;
}

From source file:com.github.wolfdogs.kemono.util.event.RootEventManager.java

@Override
public <T extends Event> void dispatchEvent(ThrowableHandler throwableHandler, T event, Object... objects) {
    if (throwableHandler == null)
        throwableHandler = DEFAULT_THROWABLE_HANDLER;
    if (objects.length == 0)
        objects = new Object[] { new Object() };

    Class<? extends Event> type = event.getClass();
    PriorityQueue<HandlerEntry> handlerEntryQueue = new PriorityQueue<HandlerEntry>(16,
            HANDLER_ENTRY_PRIORITY_COMPARATOR);

    Map<Object, Queue<HandlerEntry>> objectEntriesMap = handlerEntryContainersMap.get(type);
    if (objectEntriesMap == null)
        return;/* w  ww . ja va2 s .co m*/

    for (Object object : objects) {
        Class<?> cls = object.getClass();

        Queue<HandlerEntry> entries = objectEntriesMap.get(object);
        if (entries != null) {
            for (HandlerEntry entry : entries)
                handlerEntryQueue.add(entry);
        }

        Class<?>[] interfaces = cls.getInterfaces();
        for (Class<?> clz : interfaces) {
            Queue<HandlerEntry> classEntries = objectEntriesMap.get(clz);
            if (classEntries != null) {
                for (HandlerEntry entry : classEntries)
                    handlerEntryQueue.add(entry);
            }
        }

        for (Class<?> clz = cls; clz != null; clz = clz.getSuperclass()) {
            Queue<HandlerEntry> classEntries = objectEntriesMap.get(clz);
            if (classEntries != null) {
                for (HandlerEntry entry : classEntries)
                    handlerEntryQueue.add(entry);
            }
        }
    }

    while (handlerEntryQueue.isEmpty() == false && event.isInterrupted() == false) {
        HandlerEntry entry = handlerEntryQueue.poll();
        EventHandler handler = entry.getHandler();

        if (handler == null)
            continue;

        try {
            handler.handleEvent(event);
        } catch (Throwable e) {
            throwableHandler.handleThrowable(e);
        }
    }
}

From source file:org.crazydog.util.spring.ClassUtils.java

/**
 * Return all interfaces that the given class implements as Set,
 * including ones implemented by superclasses.
 * <p>If the class itself is an interface, it gets returned as sole interface.
 * @param clazz the class to analyze for interfaces
 * @param classLoader the ClassLoader that the interfaces need to be visible in
 * (may be {@code null} when accepting all declared interfaces)
 * @return all interfaces that the given object implements as Set
 *///from  w ww  . j  a  v a  2s . com
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
    org.springframework.util.Assert.notNull(clazz, "Class must not be null");
    if (clazz.isInterface() && isVisible(clazz, classLoader)) {
        return Collections.<Class<?>>singleton(clazz);
    }
    Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
    while (clazz != null) {
        Class<?>[] ifcs = clazz.getInterfaces();
        for (Class<?> ifc : ifcs) {
            interfaces.addAll(getAllInterfacesForClassAsSet(ifc, classLoader));
        }
        clazz = clazz.getSuperclass();
    }
    return interfaces;
}

From source file:org.nuunframework.cli.NuunCliPlugin.java

@SuppressWarnings("unchecked")
Class<?>[] getAllInterfacesAndClasses(Class<?>[] classes) {
    if (0 == classes.length) {
        return classes;
    } else {//  w  w w.  ja  v a 2 s . com
        List<Class<?>> extendedClasses = new ArrayList<Class<?>>();
        // all interfaces hierarchy
        for (Class<?> clazz : classes) {
            if (clazz != null) {
                Class<?>[] interfaces = clazz.getInterfaces();
                if (interfaces != null) {
                    extendedClasses.addAll((List<? extends Class<?>>) Arrays.asList(interfaces));
                }
                Class<?> superclass = clazz.getSuperclass();
                if (superclass != null && superclass != Object.class) {
                    extendedClasses.addAll((List<? extends Class<?>>) Arrays.asList(superclass));
                }
            }
        }

        // Class::getInterfaces() gets only interfaces/classes
        // implemented/extended directly by a given class.
        // We need to walk the whole way up the tree.
        return (Class[]) ArrayUtils.addAll(classes,
                getAllInterfacesAndClasses(extendedClasses.toArray(new Class[extendedClasses.size()])));
    }
}

From source file:com.dianping.resource.io.util.ClassUtils.java

/**
 * Does the given class or one of its superclasses at least have one or more
 * methods with the supplied name (with any argument types)?
 * Includes non-public methods./*from w w w  .  j  a v a 2  s  .c om*/
 * @param clazz   the clazz to check
 * @param methodName the name of the method
 * @return whether there is at least one method with the given name
 */
public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
    Assert.notNull(clazz, "Class must not be null");
    Assert.notNull(methodName, "Method name must not be null");
    Method[] declaredMethods = clazz.getDeclaredMethods();
    for (Method method : declaredMethods) {
        if (method.getName().equals(methodName)) {
            return true;
        }
    }
    Class<?>[] ifcs = clazz.getInterfaces();
    for (Class<?> ifc : ifcs) {
        if (hasAtLeastOneMethodWithName(ifc, methodName)) {
            return true;
        }
    }
    return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
}

From source file:com.freetmp.common.util.ClassUtils.java

public static boolean hasAtLeastOneMethodWithName(Class<?> clazz, String methodName) {
    Assert.notNull(clazz, "Class must not be null");
    Assert.notNull(methodName, "Method name must not be null");
    Method[] declaredMethods = clazz.getDeclaredMethods();
    for (Method method : declaredMethods) {
        if (method.getName().equals(methodName)) {
            return true;
        }//from   ww w  . j av a  2 s . com
    }
    Class<?>[] ifcs = clazz.getInterfaces();
    for (Class<?> ifc : ifcs) {
        if (hasAtLeastOneMethodWithName(ifc, methodName)) {
            return true;
        }
    }
    return (clazz.getSuperclass() != null && hasAtLeastOneMethodWithName(clazz.getSuperclass(), methodName));
}