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:ClassComparator.java

/**
 * Checks, whether the given classes are comparable. This method will return
 * true, if one of the classes is assignable from the other class.
 * // ww  w.  j  a  v a 2 s.  co m
 * @param c1
 *          the first class to compare
 * @param c2
 *          the second class to compare
 * @return true, if the classes share a direct relation, false otherwise.
 */
public boolean isComparable(final Class c1, final Class c2) {
    return (c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1));
}

From source file:module.workflow.domain.utils.WorkflowCommentCounter.java

public WorkflowCommentCounter(Class workflowClass) {
    Class<WorkflowProcess> workflowProcessClass = WorkflowProcess.class;
    if (!workflowProcessClass.isAssignableFrom(workflowClass)) {
        throw new IllegalArgumentException("Wrong class type provided to the WorkflowCommentCounter");
    }// ww  w.  j a  v  a  2  s. c o  m
    this.classToFilter = workflowClass;
}

From source file:com.evolveum.midpoint.schema.util.WfContextUtil.java

@SuppressWarnings("unchecked")
public static <T extends CaseEventType> List<T> getEventsForCurrentStage(@NotNull WfContextType wfc,
        @NotNull Class<T> clazz) {
    if (wfc.getStageNumber() == null) {
        throw new IllegalArgumentException(
                "No stage number in workflow context; pid = " + wfc.getProcessInstanceId());
    }//  w w w.j a  v a  2s.  c  o m
    int stageNumber = wfc.getStageNumber();
    return wfc.getEvent().stream().filter(e -> clazz.isAssignableFrom(e.getClass())
            && e.getStageNumber() != null && stageNumber == e.getStageNumber()).map(e -> (T) e)
            .collect(Collectors.toList());
}

From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java

private static int isTypeAssignableFrom(Type targetType, Type sourceType) {
    Class<?> targetClass = toClass(targetType);
    Class<?> sourceClass = toClass(sourceType);

    int rate = 5;
    if (!targetType.equals(sourceType)) {
        rate = 4;/*www  . j a  v  a 2 s  .  c o  m*/
        boolean b = targetClass.isAssignableFrom(sourceClass);
        if (b) {
            Class<?> targetElementClass = getElementType(targetType);
            if (targetElementClass != null) {
                Class<?> sourceElementClass = getElementType(sourceType);
                if (sourceElementClass != null) {
                    return isTypeAssignableFrom(targetElementClass, sourceElementClass);
                }
            }
        } else if (targetClass.isPrimitive()) {
            targetClass = MethodUtils.toNonPrimitiveClass(targetClass);
            b = targetClass.isAssignableFrom(sourceClass);
        }

        if (!b) {
            b = Number.class.isAssignableFrom(targetClass) && Number.class.isAssignableFrom(sourceClass);
        }
        if (!b) {
            rate = 0;
        }
    }
    return rate;
}

From source file:shiver.me.timbers.spring.security.modification.SecurityFilterChainModifier.java

@Override
@SuppressWarnings("unchecked")
public <F extends Filter> void modifyLink(SecurityFilterChain filterChain, Class<F> filterType,
        Modifier<F> modifier) {
    for (Filter filter : filterChain.getFilters()) {
        if (filterType.isAssignableFrom(filter.getClass())) {
            modifier.modify((F) filter);
        }/*from  w w  w .j  av a  2 s.  c om*/
    }
}

From source file:org.dkpro.lab.engine.impl.DefaultTaskExecutionService.java

@Override
public TaskExecutionEngine createEngine(Task aConfiguration) {
    try {/*from w  ww.j a v a2s.  c om*/
        for (Class<? extends Task> taskClass : map.keySet()) {
            if (taskClass.isAssignableFrom(aConfiguration.getClass())) {
                TaskExecutionEngine engine = map.get(taskClass).newInstance();
                engine.setContextFactory(contextFactory);
                beanFactory.autowireBean(engine);
                return engine;
            }
        }
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }

    throw new IllegalArgumentException(
            "No engine registered for type [" + aConfiguration.getClass().getName() + "]");
}

From source file:kenh.xscript.elements.If.java

private Element getChild(Class c) {
    Vector<Element> elements = this.getChildren();
    for (Element e : elements) {
        if (c.isAssignableFrom(e.getClass()))
            return e;
    }//ww w.  j a va2s  .  c  o m

    return null;
}

From source file:io.pivotal.spring.cloud.cloudfoundry.HystrixAmqpServiceInfoCreatorTest.java

private void assertServiceNotFoundOfType(List<ServiceInfo> serviceInfos,
        Class<? extends ServiceInfo> expected) {
    for (ServiceInfo serviceInfo : serviceInfos) {
        if (expected.isAssignableFrom(serviceInfo.getClass())) {
            fail("ServiceInfo of type " + expected.getName() + " should not have been found");
        }//from   ww w .jav a 2 s. co  m
    }
}

From source file:org.brushingbits.jnap.common.bean.visitor.HibernateTypeResolver.java

/**
 * /*from ww w. jav  a 2s. c o m*/
 * @param collectionType
 * @return
 */
protected Class<?> getUnderlyingCollectionType(Class<?> collectionType) {
    Class<?> underlyingType = null;
    for (Class<?> key : COLLECTIONS_MAPPING.keySet()) {
        if (key.isAssignableFrom(collectionType)) {
            underlyingType = COLLECTIONS_MAPPING.get(key);
            break;
        }
    }
    Assert.notNull(underlyingType);
    return underlyingType;
}

From source file:py.una.pol.karaku.dao.entity.watchers.WatcherHandler.java

/**
 * @param clazz/*  w w w . j  av  a2  s .  c  om*/
 * @return
 */
private <T> Set<Watcher<?>> getWatchers(Class<T> clazz) {

    Set<Watcher<?>> currentWatchers = new HashSet<Watcher<?>>();
    for (Entry<Class<?>, List<Watcher<?>>> entry : maps.entrySet()) {

        Class<?> oClazz = entry.getKey();
        if (oClazz.isAssignableFrom(clazz)) {
            currentWatchers.addAll(entry.getValue());
        }
    }
    return currentWatchers;
}