Example usage for org.apache.commons.lang ClassUtils isAssignable

List of usage examples for org.apache.commons.lang ClassUtils isAssignable

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils isAssignable.

Prototype


public static boolean isAssignable(Class<?> cls, Class<?> toClass) 

Source Link

Document

Checks if one Class can be assigned to a variable of another Class.

Unlike the Class#isAssignableFrom(java.lang.Class) method, this method takes into account widenings of primitive classes and nulls.

Primitive widenings allow an int to be assigned to a long, float or double.

Usage

From source file:org.epochx.tools.util.TypeUtils.java

/**
 * Returns true if the given collection contains an element which represents
 * a class which is the same as or is a sub type of the given class.
 * /*from  ww  w . ja  va2  s. c o m*/
 * @param collection the collection to seach for a class that is assignable
 *        from amongst.
 * @param cls the class that is being searched against the given collection.
 * @return true if the given collection contains a Class which is the same
 *         as or a subtype of the given class parameter. It returns false
 *         otherwise.
 */
public static boolean containsSub(final Class<?>[] collection, final Class<?> cls) {
    for (final Class<?> c : collection) {
        if (ClassUtils.isAssignable(c, cls)) {
            return true;
        }
    }

    return false;
}

From source file:org.epochx.tools.util.TypeUtils.java

public static boolean containsSuper(final Class<?>[] collection, final Class<?> cls) {
    for (final Class<?> c : collection) {
        if (ClassUtils.isAssignable(cls, c)) {
            return true;
        }//from w w  w.  j  a  va 2 s  .co m
    }

    return false;
}

From source file:org.epochx.tools.util.TypeUtils.java

public static boolean allSub(final Class<?>[] collection, final Class<?> cls) {
    for (final Class<?> c : collection) {
        if (!ClassUtils.isAssignable(c, cls)) {
            return false;
        }/*from ww  w .ja  v a 2  s.  co  m*/
    }

    return true;
}

From source file:org.epochx.tools.util.TypeUtils.java

public static boolean allSuper(final Class<?>[] collection, final Class<?> cls) {
    for (final Class<?> c : collection) {
        if (!ClassUtils.isAssignable(cls, c)) {
            return false;
        }// w  w  w  .  j  av  a  2 s.com
    }

    return true;
}

From source file:org.jdto.util.MemberUtils.java

/**
 * Gets the number of steps required needed to turn the source class into
 * the destination class. This represents the number of steps in the object
 * hierarchy graph.//from w w w .  java2s.  c om
 *
 * @param srcClass The source class
 * @param destClass The destination class
 * @return The cost of transforming an object
 */
private static float getObjectTransformationCost(Class srcClass, Class destClass) {
    if (destClass.isPrimitive()) {
        return getPrimitivePromotionCost(srcClass, destClass);
    }
    float cost = 0.0f;
    while (srcClass != null && !destClass.equals(srcClass)) {
        if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass)) {
            // slight penalty for interface match.
            // we still want an exact match to override an interface match,
            // but
            // an interface match should override anything where we have to
            // get a superclass.
            cost += 0.25f;
            break;
        }
        cost++;
        srcClass = srcClass.getSuperclass();
    }
    /*
     * If the destination class is null, we've travelled all the way up to
     * an Object match. We'll penalize this by adding 1.5 to the cost.
     */
    if (srcClass == null) {
        cost += 1.5f;
    }
    return cost;
}

From source file:org.kuali.rice.krad.uif.widget.RichTable.java

private String getSortType(Class<?> dataTypeClass) {
    String sortType = UifConstants.TableToolsValues.STRING;
    if (ClassUtils.isAssignable(dataTypeClass, KualiPercent.class)) {
        sortType = UifConstants.TableToolsValues.PERCENT;
    } else if (ClassUtils.isAssignable(dataTypeClass, KualiInteger.class)
            || ClassUtils.isAssignable(dataTypeClass, KualiDecimal.class)) {
        sortType = UifConstants.TableToolsValues.CURRENCY;
    } else if (ClassUtils.isAssignable(dataTypeClass, Timestamp.class)) {
        sortType = "date";
    } else if (ClassUtils.isAssignable(dataTypeClass, java.sql.Date.class)
            || ClassUtils.isAssignable(dataTypeClass, java.util.Date.class)) {
        sortType = UifConstants.TableToolsValues.DATE;
    } else if (ClassUtils.isAssignable(dataTypeClass, Number.class)) {
        sortType = UifConstants.TableToolsValues.NUMERIC;
    }/*ww w.j a v  a 2s  .c  om*/
    return sortType;
}

From source file:org.kuali.rice.krad.uif.widget.TableTools.java

/**
 * Constructs the sort data type for each datatable columns.
 *///from w  w w. j  a  v a  2s  .  c  o  m
protected String constructTableColumnOptions(boolean isSortable, Class dataTypeClass, String sortType) {
    String colOptions = "null";

    if (!isSortable || dataTypeClass == null || sortType == null) {
        colOptions = "{ \"" + UifConstants.TableToolsKeys.SORTABLE + "\" : false } ";
    } else {
        if (ClassUtils.isAssignable(dataTypeClass, KualiPercent.class)) {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" , \""
                    + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + UifConstants.TableToolsValues.PERCENT
                    + "\" } ";
        } else if (ClassUtils.isAssignable(dataTypeClass, KualiInteger.class)
                || ClassUtils.isAssignable(dataTypeClass, KualiDecimal.class)) {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" , \""
                    + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + UifConstants.TableToolsValues.CURRENCY
                    + "\" } ";
        } else if (ClassUtils.isAssignable(dataTypeClass, Timestamp.class)) {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" , \""
                    + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + "date" + "\" } ";
        } else if (ClassUtils.isAssignable(dataTypeClass, java.sql.Date.class)
                || ClassUtils.isAssignable(dataTypeClass, java.util.Date.class)) {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" , \""
                    + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + UifConstants.TableToolsValues.DATE
                    + "\" } ";
        } else if (ClassUtils.isAssignable(dataTypeClass, Number.class)) {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" , \""
                    + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \"" + UifConstants.TableToolsValues.NUMERIC
                    + "\" } ";
        } else {
            colOptions = "{ \"" + UifConstants.TableToolsKeys.SORT_DATA_TYPE + "\" : \"" + sortType + "\" } ";
        }
    }

    return colOptions;
}

From source file:org.lexevs.cache.AbstractMethodCachingBean.java

private Object returnResult(Object result, CacheMethod cacheMethodAnnotation) {
    if (result != null && cacheMethodAnnotation.cloneResult()
            && ClassUtils.isAssignable(result.getClass(), Serializable.class)) {
        return DaoUtility.deepClone((Serializable) result);
    } else {/* ww w . ja v  a  2s.c o m*/
        return result;
    }
}

From source file:org.lexevs.dao.database.scheme.PersistenceSchemeFactory.java

@Override
public void afterPropertiesSet() throws Exception {
    for (ExtensionDescription ed : myClassLoader.getExtensionDescriptions()) {

        Class<?> extensionBaseClass;
        try {//from  w  ww .j  a  v  a2s  . com
            extensionBaseClass = Class.forName(ed.getExtensionBaseClass(), true, myClassLoader);
        } catch (ClassNotFoundException e1) {
            logger.warn("Extension: " + ed.getName() + " cannot be loaded, " + "class: "
                    + ed.getExtensionClass() + " could not be found.");
            continue;
        }

        if (ClassUtils.isAssignable(extensionBaseClass, PersistenceScheme.class)) {
            this.persistenceSchemes.add((PersistenceScheme) Class
                    .forName(ed.getExtensionClass(), true, myClassLoader).newInstance());
        }
    }
}

From source file:org.lexevs.dao.database.service.event.registry.ExtensionLoadingListenerRegistry.java

@Override
public void afterPropertiesSet() throws Exception {
    for (ExtensionDescription ed : myClassLoader.getExtensionDescriptions()) {

        Class<?> extensionBaseClass;
        try {/*from www .j  a  v  a2s  . c  o  m*/
            extensionBaseClass = Class.forName(ed.getExtensionBaseClass(), true, myClassLoader);
        } catch (ClassNotFoundException e1) {
            getLogger().warn("Extension: " + ed.getName() + " cannot be loaded, " + "class: "
                    + ed.getExtensionClass() + " could not be found.");
            continue;
        }

        if (ClassUtils.isAssignable(extensionBaseClass, DatabaseServiceEventListener.class)) {
            this.registerListener((DatabaseServiceEventListener) Class
                    .forName(ed.getExtensionClass(), true, myClassLoader).newInstance());
        }
    }
}