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.gs.obevo.dbmetadata.deepcompare.DeepCompareUtil.java

private MutableCollection<ClassCompareInfo> getClassCompareInfos(final Class clazz) {
    if (!this.classCompareInfoMap.containsKey(clazz)) {
        // We may have defined the comparison on a generalization (interface or superclass), so we check if there
        // are any compatible classes to check
        RichIterable<Class> realizedClasses = this.classCompareInfoMap.keysView()
                .select(new Predicate<Class>() {
                    @Override/*  w  w w  .j a v  a 2  s .  co m*/
                    public boolean accept(Class each) {
                        return each.isAssignableFrom(clazz);
                    }
                });

        RichIterable<ClassCompareInfo> realizedClassCompareInfos = realizedClasses
                .flatCollect(new Function<Class, MutableCollection<ClassCompareInfo>>() {
                    @Override
                    public MutableCollection<ClassCompareInfo> valueOf(Class realizedClass) {
                        return DeepCompareUtil.this.classCompareInfoMap.get(realizedClass);
                    }
                });

        this.classCompareInfoMap.putAll(clazz, realizedClassCompareInfos.toList());
    }
    return this.classCompareInfoMap.get(clazz);
}

From source file:org.motechproject.server.event.annotations.MotechListenerOrderedParametersProxy.java

@Override
public void callHandler(MotechEvent event) {
    Map<String, Object> params = event.getParameters();
    List<Object> args = new ArrayList<Object>();
    int i = 0;//from   w w w  .j  av a 2s  .co  m
    for (Class<?> t : method.getParameterTypes()) {
        Object param = params.get(Integer.toString(i));
        if (param != null && t.isAssignableFrom(param.getClass())) {
            args.add(param);
            i++;
        } else if (params.containsKey(Integer.toString(i)) && !t.isPrimitive() && param == null) {
            args.add(param);
            i++;
        } else {
            logger.warn(String.format(
                    "Method: %s parameter: #%d of type: %s is not available in the event: %s. Handler skiped...",
                    method.toGenericString(), i, t.getName(), event));
            return;
        }
    }
    ReflectionUtils.invokeMethod(method, bean, args.toArray());
}

From source file:org.jasig.portlet.blackboardvcportlet.security.DelegatingPermissionEvaluator.java

private PermissionTester<Object> resolvePermissionTester(Class<? extends Object> targetType) {
    PermissionTester<Object> tester = permissionTesterResolutionCache.get(targetType);
    if (tester != null) {
        return tester;
    }//from  w w w. j a v  a  2 s.  com

    for (final Map.Entry<Class<Object>, PermissionTester<Object>> permissionTesterEntry : this.permissionTesters
            .entrySet()) {
        final Class<?> testerType = permissionTesterEntry.getKey();
        if (testerType.isAssignableFrom(targetType)) {
            tester = permissionTesterEntry.getValue();
            break;
        }
    }

    if (tester == null) {
        logger.warn(
                "No PermissionTester registered for {}, AlwaysDenyPermissionTester will be used for this type",
                targetType);
        tester = AlwaysDenyPermissionTester.INSTANCE;
    }
    permissionTesterResolutionCache.put(targetType, tester);

    return tester;
}

From source file:jenkins.authentication.tokens.api.AuthenticationTokenSource.java

/**
 * Checks if this source produces the specified token type.
 *
 * @param tokenClass the token type./*from www  . j  ava  2  s . c  om*/
 * @param <T>        the token type.
 * @return {@code true} if and only if this source can produce tokens of the specified type.
 */
public final <T> boolean produces(@NonNull Class<T> tokenClass) {
    return tokenClass.isAssignableFrom(this.tokenClass);
}

From source file:net.abhinavsarkar.spelhelper.ImplicitMethodResolver.java

@Override
public MethodExecutor resolve(final EvaluationContext context, final Object targetObject, final String name,
        final List<TypeDescriptor> argumentTypes) throws AccessException {
    if (targetObject == null) {
        return null;
    }//from  ww w.j a  va  2  s  . c  o  m
    Class<?> type = targetObject.getClass();
    String cacheKey = type.getName() + "." + name;
    if (CACHE.containsKey(cacheKey)) {
        MethodExecutor executor = CACHE.get(cacheKey);
        return executor == NULL_ME ? null : executor;
    }

    Method method = lookupMethod(context, type, name);
    if (method != null) {
        int modifiers = method.getModifiers();
        if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) {
            Class<?>[] parameterTypes = method.getParameterTypes();
            Class<?> firstParamType = parameterTypes[0];
            if (parameterTypes.length > 0 && firstParamType.isAssignableFrom(type)) {
                List<TypeDescriptor> newArgumentTypes = new ArrayList<TypeDescriptor>();
                newArgumentTypes.add(TypeDescriptor.valueOf(firstParamType));
                newArgumentTypes.addAll(argumentTypes);

                MethodExecutor executor = delegate.resolve(context, method.getDeclaringClass(), name,
                        newArgumentTypes);
                MethodExecutor wrappedExecutor = executor == null ? null : new ImplicitMethodExecutor(executor);
                if (wrappedExecutor == null) {
                    CACHE.putIfAbsent(cacheKey, NULL_ME);
                }
                return wrappedExecutor;
            }
        }
    }
    CACHE.putIfAbsent(cacheKey, NULL_ME);
    return null;
}

From source file:org.shredzone.commons.view.impl.ViewContextImpl.java

@Override
public <T> void putTypedArgument(Class<T> type, T value) {
    if (value != null && !type.isAssignableFrom(value.getClass())) {
        throw new IllegalArgumentException(
                "value must be an instance of " + type.getName() + ", but is " + value.getClass().getName());
    }/*w w w.  java 2  s  . c  o  m*/
    typedValueMap.put(type, value);
}

From source file:org.camunda.bpm.ext.sdk.impl.variables.AbstractPrimitiveValueSerializer.java

@SuppressWarnings("unchecked")
public T deserializeValue(TypedValueDto object, ObjectMapper objectMapper) {
    Object value = object.getValue();

    Class<?> javaType = type.getJavaType();
    Object mappedValue = null;/*w  w  w .  j  a va  2  s  . c  om*/
    try {
        if (value != null) {
            if (javaType.isAssignableFrom(value.getClass())) {
                mappedValue = value;
            } else {
                // use jackson to map the value to the requested java type
                mappedValue = objectMapper.readValue("\"" + value + "\"", javaType);
            }
        }
        return (T) type.createValue(mappedValue, object.getValueInfo());
    } catch (Exception e) {
        throw new CamundaClientException(
                "Could not deserialize value of type " + object.getType() + ", value: " + value, e);
    }
}

From source file:com.github.dozermapper.core.classmap.ClassMappings.java

private boolean isInterfaceImplementation(Class<?> type, Class<?> mappingType) {
    return mappingType.isInterface() && mappingType.isAssignableFrom(type);
}

From source file:de.pixida.logtest.designer.automaton.BaseEdge.java

boolean sourceNodeIsOfType(final Class<?> clz) {
    Validate.notNull(clz);/*from w ww  . j a v  a  2s .  com*/
    Validate.notNull(this.sourceNode);
    return clz.isAssignableFrom(this.sourceNode.getClass());
}

From source file:de.pixida.logtest.designer.automaton.BaseEdge.java

boolean targetNodeIsOfType(final Class<?> clz) {
    Validate.notNull(clz);/*  ww  w. j a v a 2s .  c o  m*/
    Validate.notNull(this.targetNode);
    return clz.isAssignableFrom(this.targetNode.getClass());
}