當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。