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:com.fujitsu.dc.core.odata.DcExpressionParser.java

private static <T extends CommonExpression> void assertType(CommonExpression expression, Class<T> type) {
    if (!type.isAssignableFrom(expression.getClass())) {
        throw new RuntimeException("Expected " + type.getSimpleName());
    }//  w w  w  .  j av  a2 s.c  o m
}

From source file:jp.go.nict.langrid.p2pgridbasis.data.langrid.converter.LangridStringConverter.java

public Object convert(Class type, Object value) {
    if (value == null) {
        return ((String) null);
    }/*from   w w w.j  a va 2  s .c  o m*/

    if (String.class.equals(type)) {
        for (Class<?> clazz : converters.keySet()) {
            if (clazz.isAssignableFrom(value.getClass())) {
                return converters.get(clazz).convert(type, value);
            }
        }
    }

    return value.toString();
}

From source file:com.flexive.faces.FxJsfUtils.java

/**
 * Recursively search for the first child of the given class type for the component.
 *
 * @param component the component to be searched
 * @param childType the required child type
 * @return the first child of the given type, or null if no child was found.
 *//* w ww . ja  va 2s. co m*/
public static <T extends UIComponent> T findChild(UIComponent component, Class<T> childType) {
    for (Object item : component.getChildren()) {
        final UIComponent child = (UIComponent) item;
        if (childType.isAssignableFrom(child.getClass())) {
            return childType.cast(child);
        }
        // search in this child's children
        final T nestedChild = findChild(child, childType);
        if (nestedChild != null) {
            return nestedChild;
        }
    }
    return null;
}

From source file:org.arrow.model.definition.conditional.introduction.ConditionalEventPublisherIntroduction.java

/**
 * {@inheritDoc}//from   www.j a v a 2s.  co m
 */
@Override
protected Object doProceed(MethodInvocation mi) throws Throwable {

    Method method = mi.getMethod();
    Class<?> dc = method.getDeclaringClass();
    if (dc.isAssignableFrom(Execution.class) && method.getName().equals("execute")) {
        Execution execution = (Execution) mi.getArguments()[0];
        ExecutionService service = (ExecutionService) mi.getArguments()[1];
        publishConditionalEvent(execution, service);
    }

    return mi.proceed();
}

From source file:fr.cvlaminck.merging.impl.DefaultValueMergers.java

public DefaultValueMergers() {
    this.registeredMergerTypes = new TreeSet<Class<?>>(new Comparator<Class<?>>() {
        @Override/*from w  w  w  .  jav a  2 s  .  com*/
        public int compare(Class<?> c1, Class<?> c2) {
            if (c2.isAssignableFrom(c1))
                return -1;
            return 1;
        }
    });
    this.mergers = new HashMap<>();
}

From source file:org.devware.batch.validator.ItemValidator.java

@Override
public boolean supports(Class<?> arg0) {
    return arg0.isAssignableFrom(Item.class);
}

From source file:com.intellij.lang.jsgraphql.ide.project.JSGraphQLLanguageUIProjectService.java

private static void showToolWindowContent(@NotNull Project project, @NotNull Class<?> contentClass) {
    UIUtil.invokeLaterIfNeeded(() -> {
        final ToolWindow toolWindow = ToolWindowManager.getInstance(project)
                .getToolWindow(GRAPH_QL_TOOL_WINDOW_NAME);
        if (toolWindow != null) {
            toolWindow.show(() -> {// www. j av  a2  s  .c o  m
                for (Content content : toolWindow.getContentManager().getContents()) {
                    if (contentClass.isAssignableFrom(content.getComponent().getClass())) {
                        toolWindow.getContentManager().setSelectedContent(content);
                        break;
                    }
                }
            });
        }
    });
}

From source file:Classes.java

/**
 * Instantiate a java class object//  w  w  w  . j a  v a 2 s.  c  o m
 * 
 * @param expected
 *          the expected class type
 * @param property
 *          the system property defining the class
 * @param defaultClassName
 *          the default class name
 * @return the instantiated object
 */
public static Object instantiate(Class expected, String property, String defaultClassName) {
    String className = getProperty(property, defaultClassName);
    Class clazz = null;
    try {
        clazz = loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot load class " + className, e);
    }
    Object result = null;
    try {
        result = clazz.newInstance();
    } catch (InstantiationException e) {
        throw new RuntimeException("Error instantiating " + className, e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Error instantiating " + className, e);
    }
    if (expected.isAssignableFrom(clazz) == false)
        throw new RuntimeException("Class " + className + " from classloader " + clazz.getClassLoader()
                + " is not of the expected class " + expected + " loaded from " + expected.getClassLoader());
    return result;
}

From source file:de.openali.odysseus.chart.framework.model.mapper.registry.impl.DataOperatorHelper.java

public <T> IDataOperator<T> getDataOperator(final Class<T> clazz) {
    for (final Class<?> c : m_dataOperators.keySet()) {
        if (c.isAssignableFrom(clazz))
            return (IDataOperator<T>) m_dataOperators.get(c);
    }/*w ww .ja  va  2s  . co m*/

    return new DummyDataOperator<>();
}

From source file:tk.skuro.spring.processor.ObservablePostProcessor.java

@Override
public Object postProcessAfterInitialization(Object o, String s) throws BeansException {

    Class<? extends Observer> observerClass = observable.observerClass();
    if (observerClass.isAssignableFrom(o.getClass())) {
        // register it!
        observable.addObserver((SpringObserver) o);
    }/*from  ww w . j ava2  s.co  m*/

    // leave untouched
    return o;
}