Example usage for java.lang Class isInstance

List of usage examples for java.lang Class isInstance

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInstance(Object obj);

Source Link

Document

Determines if the specified Object is assignment-compatible with the object represented by this Class .

Usage

From source file:de.fu_berlin.inf.dpp.intellij.project.filesystem.IntelliJFolderImpl.java

@Override
public Object getAdapter(Class<? extends IResource> clazz) {
    if (clazz.isInstance(this)) {
        return this;
    }/*  w  w w. ja va2 s . co m*/

    return null;
}

From source file:cn.com.loopj.android.http.RetryHandler.java

protected boolean isInList(HashSet<Class<?>> list, Throwable error) {
    for (Class<?> aList : list) {
        if (aList.isInstance(error)) {
            return true;
        }/*ww  w . j a  va2s .c  om*/
    }
    return false;
}

From source file:com.microsoft.applicationinsights.web.spring.InterceptorRegistryTests.java

private <T> Annotation getAnnotationByType(List<Annotation> annotationList, Class<T> tClass) {
    for (Annotation annotation : annotationList) {
        if (tClass.isInstance(annotation)) {
            return annotation;
        }/*from   w ww.  j  a  v a2 s  .co m*/
    }

    return null;
}

From source file:com.louding.frame.http.download.RetryHandler.java

protected boolean isInList(HashSet<Class<?>> list, Throwable tr) {
    for (Class<?> clazz : list) {
        if (clazz.isInstance(tr)) {
            return true;
        }/*w ww .  j av  a  2 s  .co  m*/
    }
    return false;
}

From source file:com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.java

/**
 * Validates that the facesContext is not null, the uiComponent is not null,
 * and that uiComponent is assignment-compatible with the
 * validComponentType. Pass a null parameter for validComponentType to avoid
 * any type checking./*from  w  w w  .jav a 2s.com*/
 *
 * @param facesContext
 * @param uiComponent
 * @param validComponentType
 * @throws NullPointerException if either of the facesContext or the
 *                              uiComponent parameters are null or
 *                              if a parent form is not
 *                              found when the given UIComponent
 *                              is a UIInput or UICommand,
 *                              IllegalArgumentException if the
 *                              validComponentType is not null and the
 *                              uiComponent is not assignable to the given
 *                              type.
 */
public static void validateParameters(FacesContext facesContext, UIComponent uiComponent,
        Class validComponentType) {

    if (facesContext == null) {
        throw new NullPointerException("Invalid Parameter - FacesContext instance must not be null");
    }
    if (uiComponent == null) {
        throw new NullPointerException("Invalid Parameter - UIComponent instance must not be null");
    }
    if (!Beans.isDesignTime() && validComponentType != null && !(validComponentType.isInstance(uiComponent))) {
        throw new IllegalArgumentException("Invalid Parameter - UIComponent class should be ["
                + validComponentType + "] but it is an instance of [" + uiComponent.getClass() + "]");
    }

    if (log.isDebugEnabled()) {
        if ((uiComponent instanceof UIInput) || (uiComponent instanceof UICommand)) {
            if (findForm(uiComponent) == null) {
                log.debug("Missing Form - the UIComponent of type [" + uiComponent.getClass()
                        + "] requires a containing form.");
            }
        }
    }

}

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

public static Class getResourceClass(Resource resource) {
    for (Class c : getResourceClassList()) {
        if (c.isInstance(resource))
            return c;
    }//w ww. java2s .com
    logger.trace("Class Not Found for FHIR resource:" + resource.getId());
    return null;

}

From source file:com.ab.http.RetryHandler.java

/**
 * Checks if is in list.//from w  ww  .  j  a  va  2s  .c  o m
 *
 * @param list the list
 * @param error the error
 * @return true, if is in list
 */
protected boolean isInList(HashSet<Class<?>> list, Throwable error) {
    for (Class<?> aList : list) {
        if (aList.isInstance(error)) {
            return true;
        }
    }
    return false;
}

From source file:com.google.gerrit.httpd.ReviewDbDataSourceProvider.java

private void closeDataSource(final DataSource ds) {
    try {/*  ww w  .  ja  va2s. c  om*/
        Class<?> type = Class.forName("org.apache.commons.dbcp.BasicDataSource");
        if (type.isInstance(ds)) {
            type.getMethod("close").invoke(ds);
            return;
        }
    } catch (Throwable bad) {
        // Oh well, its not a Commons DBCP pooled connection.
    }

    try {
        Class<?> type = Class.forName("com.mchange.v2.c3p0.DataSources");
        if (type.isInstance(ds)) {
            type.getMethod("destroy", DataSource.class).invoke(null, ds);
            return;
        }
    } catch (Throwable bad) {
        // Oh well, its not a c3p0 pooled connection.
    }
}

From source file:com.consol.citrus.admin.converter.endpoint.AbstractEndpointConverter.java

/**
 *
 * @param setter/*from  ww w  .ja  v  a 2 s. com*/
 * @param value
 * @return
 */
private Object getMethodArgument(Method setter, String value) {
    Class<?> type = setter.getParameterTypes()[0];
    if (type.isInstance(value)) {
        return type.cast(value);
    }

    try {
        return new SimpleTypeConverter().convertIfNecessary(value, type);
    } catch (ConversionNotSupportedException e) {
        if (String.class.equals(type)) {
            return value.toString();
        }

        throw new ApplicationRuntimeException("Unable to convert method argument type", e);
    }
}

From source file:multichain.command.builders.QueryBuilderCommon.java

@SuppressWarnings("rawtypes")
protected boolean verifyInstance(Object obj, Class TheClass) {
    return TheClass.isInstance(obj);
}