当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils.wrapperToPrimitive方法代码示例

本文整理汇总了Java中org.apache.commons.lang.ClassUtils.wrapperToPrimitive方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.wrapperToPrimitive方法的具体用法?Java ClassUtils.wrapperToPrimitive怎么用?Java ClassUtils.wrapperToPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.ClassUtils的用法示例。


在下文中一共展示了ClassUtils.wrapperToPrimitive方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPrimitivePromotionCost

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Get the number of steps required to promote a primitive number to another
 * type.
 * @param srcClass the (primitive) source class
 * @param destClass the (primitive) destination class
 * @return The cost of promoting the primitive
 */
private static float getPrimitivePromotionCost(final Class srcClass, final Class destClass) {
    float cost = 0.0f;
    Class cls = srcClass;
    if (!cls.isPrimitive()) {
        // slight unwrapping penalty
        cost += 0.1f;
        cls = ClassUtils.wrapperToPrimitive(cls);
    }
    for (int i = 0; cls != destClass && i < ORDERED_PRIMITIVE_TYPES.length; i++) {
        if (cls == ORDERED_PRIMITIVE_TYPES[i]) {
            cost += 0.1f;
            if (i < ORDERED_PRIMITIVE_TYPES.length - 1) {
                cls = ORDERED_PRIMITIVE_TYPES[i + 1];
            }
        }
    }
    return cost;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:MemberUtils.java

示例2: setFieldFromObject

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Set a field of an object with a value, also if the field is of primitive type.
 * 
 * Apart from this, it mimics behavior from java.reflection.Field.set(Object, Object).
 */
public static void setFieldFromObject(Object object, Field field, Object value) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
	if (!field.getType().isPrimitive()) {
		field.set(object, value);
		return;
	}
	
	Class<?> primitiveClass = value.getClass();
	
	if (!primitiveClass.isPrimitive()) {
		primitiveClass = ClassUtils.wrapperToPrimitive(primitiveClass);
		if (primitiveClass == null) {
			throw new IllegalArgumentException(field + " is a primitive field but the value is neither primitive nor wrapper.");
		}
	}
	
	String assignerName = "set" + WordUtils.capitalize(primitiveClass.getSimpleName());
	
	Method assigner = Field.class.getMethod(assignerName, new Class<?>[] {Object.class, primitiveClass});
	assigner.invoke(field, new Object[] {object, value});
	
}
 
开发者ID:corradomonti,项目名称:llamafur,代码行数:27,代码来源:ReflectionUtils.java

示例3: getPrimitivePromotionCost

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
    * Get the number of steps required to promote a primitive number to another type.
    * @param srcClass the (primitive) source class
    * @param destClass the (primitive) destination class
    * @return The cost of promoting the primitive
    */
   @SuppressWarnings("rawtypes")
private static float getPrimitivePromotionCost(final Class srcClass,
           final Class destClass) {
       float cost = 0.0f;
       Class cls = srcClass;
       if (!cls.isPrimitive()) {
           // slight unwrapping penalty
           cost += 0.1f;
           cls = ClassUtils.wrapperToPrimitive(cls);
       }
       for (int i = 0; cls != destClass && i < ORDERED_PRIMITIVE_TYPES.length; i++) {
           if (cls == ORDERED_PRIMITIVE_TYPES[i]) {
               cost += 0.1f;
               if (i < ORDERED_PRIMITIVE_TYPES.length - 1) {
                   cls = ORDERED_PRIMITIVE_TYPES[i + 1];
               }
           }
       }
       return cost;
   }
 
开发者ID:losvald,项目名称:sglj,代码行数:27,代码来源:RmiUtils.java

示例4: toString

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Gets a custom string representation based on the parameter (0 argument) methodName.
 *
 * @param obj
 * @param klass
 * @param methodName
 * @return
 */
public static String toString(final Object obj, final Class<?> klass, String methodName)
        throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    if (StringUtils.isBlank(methodName)) {
        methodName = "toString";
    }

    boolean isPrimitiveOrWrapped =
            obj.getClass().isPrimitive() || ClassUtils.wrapperToPrimitive(obj.getClass()) != null;

    if (isPrimitiveOrWrapped) {
        return String.valueOf(obj);
    } else if (Date.class.equals(klass)) {
        return ((Date) obj).toString();
    } else if (Calendar.class.equals(klass)) {
        return ((Calendar) obj).getTime().toString();
    } else if(isArray(obj)) {
        return toStringFromArray(obj);
    } else {
        Method method = klass.getMethod(methodName);
        return (String) method.invoke(obj);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:31,代码来源:TypeUtil.java

示例5: isSimpleProperty

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public static Boolean isSimpleProperty(Class<?> clazz) {
	if (clazz.isPrimitive()) {
		return true;
	} else if (ClassUtils.wrapperToPrimitive(clazz) != null) {
		return true;
	} else if (String.class.isAssignableFrom(clazz)) {
		return true;
	} else if (Date.class.isAssignableFrom(clazz)) {
		return true;
	} else if (BigDecimal.class.isAssignableFrom(clazz)) {
		return true;
	}
	return false;
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:15,代码来源:SimplePropertyUtil.java

示例6: isScalarValue

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public static boolean isScalarValue (Object value)
{
  return ClassUtils.wrapperToPrimitive (value.getClass ()) != null;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:5,代码来源:ConfigurationUtilHelpers.java

示例7: getTypeCode

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private static char getTypeCode(Object wrapper) {
    Class primitiveType = ClassUtils.wrapperToPrimitive(wrapper.getClass());
    ObjectStreamField typeCodeProvider = new ObjectStreamField(IRRELEVANT, primitiveType);
    return typeCodeProvider.getTypeCode();
}
 
开发者ID:csm,项目名称:java-sandbox,代码行数:6,代码来源:WrapperConverter.java

示例8: isScalarValue

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Checks whether the specified object is a scalar value. This method is
 * called by {@code getList()} and {@code getStringArray()} if the property
 * requested is not a string, a list, or an array. If it returns
 * <b>true</b>, the calling method transforms the value to a string and
 * returns a list or an array with this single element. This implementation
 * returns <b>true</b> if the value is of a wrapper type for a primitive
 * type.
 * 
 * @param value
 *            the value to be checked
 * @return a flag whether the value is a scalar
 * @since 1.7
 */
private boolean isScalarValue(Object value) {
	return ClassUtils.wrapperToPrimitive(value.getClass()) != null;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:18,代码来源:AbstractConfiguration.java


注:本文中的org.apache.commons.lang.ClassUtils.wrapperToPrimitive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。