Example usage for org.apache.commons.beanutils MethodUtils toNonPrimitiveClass

List of usage examples for org.apache.commons.beanutils MethodUtils toNonPrimitiveClass

Introduction

In this page you can find the example usage for org.apache.commons.beanutils MethodUtils toNonPrimitiveClass.

Prototype

public static Class toNonPrimitiveClass(Class clazz) 

Source Link

Document

Find a non primitive representation for given primitive class.

Usage

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

private static Type toNonPrimitiveClass(Type type) {
    if (type instanceof Class<?>) {
        return MethodUtils.toNonPrimitiveClass((Class<?>) type);
    }//from  w w  w  .  ja  va2 s.co  m
    return type;
}

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;/*from   ww  w .j  a v  a 2s. 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: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   ww w.  j a v a  2s.  co  m*/
    if (!b) {
        b = Number.class.isAssignableFrom(targetClass) && Number.class.isAssignableFrom(sourceClass);
    }
    return (b) ? 1 : 0;
}