Example usage for java.lang Class isAssignableFrom

List of usage examples for java.lang Class isAssignableFrom

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native boolean isAssignableFrom(Class<?> cls);

Source Link

Document

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.

Usage

From source file:at.molindo.utils.reflect.ClassUtils.java

/**
 * @return <code>true</code> if <code>cls</code> is assignable to all
 *         <code>classes</code>
 *///from  w w w.  jav  a2  s  . co  m
public static boolean isAssignableToAll(Class<?> cls, Set<Class<?>> classes) {
    if (cls == null) {
        return false;
    }
    for (Class<?> c : classes) {
        if (!c.isAssignableFrom(cls)) {
            return false;
        }
    }
    return true;
}

From source file:be.fgov.kszbcss.rhq.websphere.mbean.MBeanClient.java

private static boolean throwsException(Method method, Class<?> exceptionType) {
    for (Class<?> candidate : method.getExceptionTypes()) {
        if (candidate.isAssignableFrom(exceptionType)) {
            return true;
        }// www  . j a  va2  s.c  o m
    }
    return false;
}

From source file:Main.java

public static <T> Collection<T> getObjectsOfType(Collection<?> input, Class<T> type, Collection<T> output) {
    if (output == null) {
        output = createEmpty(input);// w w w .j a  v a2s .com
        if (output == null)
            output = new ArrayList<T>();
    }
    for (Object o : input) {
        if (type.isAssignableFrom(o.getClass()))
            output.add((T) o);
    }
    return output;
}

From source file:com.proofpoint.jaxrs.JsonMapper.java

private static boolean canReadOrWrite(Class<?> type) {
    if (IO_CLASSES.contains(type)) {
        return false;
    }/*from   w w w  . j  a v  a2  s . c o m*/
    for (Class<?> ioClass : IO_CLASSES) {
        if (ioClass.isAssignableFrom(type)) {
            return false;
        }
    }

    return true;
}

From source file:Main.java

/**
 * Returns the first object of given type or its subtypes
 * @param clazz The class you want to return the first instance found of.
 * @param objects The collection you'd like to search.
 * @return The first instance of a specific Class found in a Collection.  Returns null if no instance is found.
 *///from   w w w  .j  a  v  a 2s . c  o  m
public static Object getFirstInstance(Class clazz, Collection objects) {
    if (objects != null && clazz != null) {
        Iterator objectsIterator = objects.iterator();
        while (objectsIterator.hasNext()) {
            Object instance = objectsIterator.next();
            if (clazz.isAssignableFrom(instance.getClass())) {
                return instance;
            }
        }
    }
    return null;
}

From source file:com.floreantpos.extension.ExtensionManager.java

public static List<FloreantPlugin> getPlugins(Class pluginClass) {
    List<FloreantPlugin> list = new ArrayList<FloreantPlugin>();

    for (FloreantPlugin floreantPlugin : getInstance().plugins) {
        if (pluginClass.isAssignableFrom(floreantPlugin.getClass())) {
            list.add(floreantPlugin);/*from   w w w  .j  ava  2  s.  co m*/
        }
    }

    return list;
}

From source file:Main.java

public static List<Component> findChildComponentsOfType(Component component, Class<?> type) {
    List<Component> foundComponents = new ArrayList<Component>();
    if (component instanceof Container) {
        Container container = (Container) component;
        for (Component child : container.getComponents()) {
            if (type.isAssignableFrom(child.getClass())) {
                foundComponents.add(child);
            }/*  ww w  . ja  v a2s . com*/
            foundComponents.addAll(findChildComponentsOfType(child, type));// recursive
        }
    }
    return foundComponents;
}

From source file:net.mlw.vlh.web.util.JspUtils.java

public static Tag getParent(Tag self, Class klass) throws JspException {
    Tag tag = self.getParent();/*w w w .  ja  v a 2 s .  c  o m*/

    while (!(klass.isAssignableFrom(tag.getClass()))) {
        tag = tag.getParent();
        if (tag == null) {
            final String message = "Parent tag of class " + klass + " of the tag's class " + self
                    + " was not found.";
            LOGGER.error(message);
            throw new JspException(message);
        }
    }
    return tag;
}

From source file:com.adaptris.core.fs.FsHelper.java

public static FileFilter logWarningIfRequired(FileFilter f) {
    try {/*  w  w  w. ja v a 2  s  .  c  om*/
        Class clz = Class.forName("org.apache.oro.io.RegexFilenameFilter");
        if (clz.isAssignableFrom(f.getClass())) {
            log.warn("{} is deprecated, use a java.util.regex.Pattern based filter instead",
                    f.getClass().getCanonicalName());
        }
    } catch (Exception e) {

    }
    return f;
}

From source file:com.netflix.nicobar.core.module.ScriptModuleUtils.java

/**
 * Find the first class in the module that is a subclasses or equal to the target class
 * @param module module to search/*w  w w.ja  va 2s . c  o  m*/
 * @param targetClass target type to search for
 * @return first instance that matches the given type
 */
@Nullable
public static Class<?> findAssignableClass(ScriptModule module, Class<?> targetClass) {
    for (Class<?> candidateClass : module.getLoadedClasses()) {
        if (targetClass.isAssignableFrom(candidateClass)) {
            return candidateClass;
        }
    }
    return null;
}