Java Reflection Interface Get getInterfaces(Class clazz)

Here you can find the source of getInterfaces(Class clazz)

Description

get Interfaces

License

Open Source License

Declaration

public static Class[] getInterfaces(Class clazz) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static Class[] getInterfaces(Class clazz) {
        List interfaces = new ArrayList();
        interfaces = getAllInterfacesExclude(clazz, null, interfaces);
        return (Class[]) (Class[]) interfaces.toArray(new Class[interfaces.size()]);
    }//w  ww . j  av a2  s.  co m

    public static Class[] getInterfaces(Class clazz, String excludes[]) {
        List interfaces = new ArrayList();
        interfaces = getAllInterfacesExclude(clazz, excludes, interfaces);
        return (Class[]) (Class[]) interfaces.toArray(new Class[interfaces.size()]);
    }

    private static List getAllInterfacesExclude(Class clazz, String itfNames[], List list) {
        if (list == null)
            list = new ArrayList();
        if (clazz != null) {
            Class interfaces[] = clazz.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                boolean needAdded = true;
                if (list.contains(interfaces[i]))
                    continue;
                if (itfNames != null) {
                    for (int j = 0; j < itfNames.length && needAdded; j++) {
                        if (!interfaces[i].getName().startsWith(itfNames[j]))
                            continue;
                        if (clazz.isInterface())
                            list.remove(clazz);
                        needAdded = false;
                    }

                }
                if (needAdded) {
                    list.add(interfaces[i]);
                    getAllInterfacesExclude(interfaces[i], itfNames, list);
                }
            }

            clazz = clazz.getSuperclass();
            getAllInterfacesExclude(clazz, itfNames, list);
        }
        return list;
    }
}

Related

  1. getImplementedInterfaceParents(Class clazz, Set classesResult)
  2. getImplementedInterfaces(Class clazz)
  3. getImplementedInterfaces(Class cl)
  4. getInterfaceInstance(Class interfaceType)
  5. getInterfaceNames(Class c)
  6. getInterfaces(Class c)
  7. getInterfaces(Class clazz)
  8. getInterfaces(Class clazz)
  9. getInterfaces(final Class type)