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.fitbur.docker.client.internal.ObjectMapperResolver.java

@Override
public ObjectMapper getContext(Class<?> type) {
    if (type.isAssignableFrom(ImageStatus.class)) {
        return camelMapper;
    }//w  w w  .  jav a  2  s  .  c o m

    return pascalMapper;
}

From source file:com.braffdev.server.core.module.mapping.requesthandler.method.parameter.handlers.HttpResponseParameterHandler.java

/**
 *
 *//*  w w  w.j a  v  a 2  s.c o m*/
@Override
public boolean canHandle(Class<?> clazz) {
    return clazz.isAssignableFrom(HttpResponse.class);
}

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

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

    boolean b = targetClass.isAssignableFrom(sourceClass) || sourceClass.isAssignableFrom(targetClass);
    if (!b && (targetClass.isPrimitive() || sourceClass.isPrimitive())) {
        targetClass = MethodUtils.toNonPrimitiveClass(targetClass);
        sourceClass = MethodUtils.toNonPrimitiveClass(sourceClass);
        b = targetClass.isAssignableFrom(sourceClass) || sourceClass.isAssignableFrom(targetClass);
    }//from  w w w. j av a2  s.  com
    if (!b) {
        b = Number.class.isAssignableFrom(targetClass) && Number.class.isAssignableFrom(sourceClass);
    }
    return (b) ? 1 : 0;
}

From source file:com.khs.sherpa.parser.StringParamParser.java

public boolean isValid(Class<?> clazz) {
    return clazz.isAssignableFrom(String.class);
}

From source file:nl.surfnet.coin.teams.service.impl.InvitationValidator.java

/**
 * {@inheritDoc}/* w w w.ja  va  2 s.  c o  m*/
 */
@Override
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(Invitation.class);
}

From source file:org.openregistry.core.web.SearchCriteriaValidator.java

public boolean supports(final Class aClass) {
    return aClass.isAssignableFrom(SearchCriteriaValidator.class);
}

From source file:de.interseroh.report.controller.ParameterFormValidator.java

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

From source file:eu.udig.catalog.jgrass.utils.JGrassCatalogUtilities.java

/**
 * Creates a {@link WritableRaster writable raster}.
 * //  w  w w.j  a v a 2 s  . c  o m
 * @param width width of the raster to create.
 * @param height height of the raster to create.
 * @param dataClass data type for the raster. If <code>null</code>, defaults to double.
 * @param sampleModel the samplemodel to use. If <code>null</code>, defaults to 
 *                  <code>new ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});</code>.
 * @param value value to which to set the raster to. If null, the default of the raster creation is 
 *                  used, which is 0.
 * @return a {@link WritableRaster writable raster}.
 */
public static WritableRaster createDoubleWritableRaster(int width, int height, Class<?> dataClass,
        SampleModel sampleModel, Double value) {
    int dataType = DataBuffer.TYPE_DOUBLE;
    if (dataClass != null) {
        if (dataClass.isAssignableFrom(Integer.class)) {
            dataType = DataBuffer.TYPE_INT;
        } else if (dataClass.isAssignableFrom(Float.class)) {
            dataType = DataBuffer.TYPE_FLOAT;
        } else if (dataClass.isAssignableFrom(Byte.class)) {
            dataType = DataBuffer.TYPE_BYTE;
        }
    }
    if (sampleModel == null) {
        sampleModel = new ComponentSampleModel(dataType, width, height, 1, width, new int[] { 0 });
    }

    WritableRaster raster = RasterFactory.createWritableRaster(sampleModel, null);
    if (value != null) {
        // autobox only once
        double v = value;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                raster.setSample(x, y, 0, v);
            }
        }
    }
    return raster;
}

From source file:net.femtoparsec.jnlmin.utils.ReflectUtils.java

public static int findClassDistance(Class<?> lower, Class<?> upper) {
    lower = boxClass(lower);/*  w  w  w  .j a  v a2  s  .  c o m*/
    upper = boxClass(upper);

    if (lower == upper) {
        return 0;
    }

    if (Number.class.isAssignableFrom(lower) && Number.class.isAssignableFrom(upper)) {
        Integer lowerDistance = NUMBER_DISTANCE_MAP.get(lower.asSubclass(Number.class));
        Integer upperDistance = NUMBER_DISTANCE_MAP.get(upper.asSubclass(Number.class));
        if (lowerDistance != null && upperDistance != null) {
            if (lowerDistance > upperDistance) {
                return -1;
            }
            return upperDistance - lowerDistance;
        }
        //lower or upper is a custom Number (like BigInteger)
        //handle it as normal classes
    }

    if (!upper.isAssignableFrom(lower)) {
        return -1;
    }

    if (upper.isInterface()) {
        if (lower.isInterface()) {
            return findIIDistance(lower, upper);
        } else {
            return findCIDistance(lower, upper);
        }
    } else {
        assert !lower.isInterface();
        return findCCDistance(lower, upper);
    }

}

From source file:grails.plugin.springsecurity.acl.access.GroovyAwareAclVoter.java

public boolean supports(final Class<?> clazz) {
    return clazz.isAssignableFrom(MethodInvocation.class);
}