/** * <p>Converts the specified array of wrapper Class objects to an array of * its corresponding primitive Class objects.</p> * * <p>This method invokes <code>wrapperToPrimitive()</code> for each element * of the passed in array.</p> * * @param classes the class array to convert, may be null or empty * @return an array which contains for each given class, the primitive class or * <b>null</b> if the original class is not a wrapper class. <code>null</code> if null input. * Empty array if an empty array passed in. * @see #wrapperToPrimitive(Class) * @since 2.4 */ public static Class[] wrappersToPrimitives(Class[] classes) { if (classes == null) { return null; } if (classes.length == 0) { return classes; } Class[] convertedClasses = new Class[classes.length]; for (int i = 0; i < classes.length; i++) { convertedClasses[i] = wrapperToPrimitive(classes[i]); } return convertedClasses; }
/** * 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; }
/** * Determines if the given object is a primitive or a wrapper to a primitive. Note, even though a * <code>String</code> may not be a primitive in the traditional sense, but it is considered one * here as it is <i>not</i> a struct. * * @param clazz input class * @return true, if the object is a primitive or a wrapper to a primitive, false otherwise. * */ private boolean isPrimitive(Class<?> clazz) { return clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null || clazz.getSimpleName().equals("String"); } }
cls = wrapperToPrimitive(cls); if (cls == null) { return false;
String offsetStr = repeat(" ", level); if (p == null || c == String.class || c.isPrimitive() || ClassUtils.wrapperToPrimitive(c) != null) { errorStr.append(offsetStr).append(name + ": [" + p + "]\n"); } else if (ClassUtils.isAssignable(c, Iterable.class)) {
/** * Returns the corresponding primitive type to a wrapper class. If the * passed in class is not a wrapper class, <b>null</b> is returned. * * @param wrapperCls the wrapper class * @return the corresponding primitive type */ private static Class<?> wrapperToPrimitive(Class<?> wrapperCls) { return ClassUtils.wrapperToPrimitive(wrapperCls); }
private boolean isPrimitive(Class<?> clazz){ boolean isPrimitiveOrWrapped = clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null; return isPrimitiveOrWrapped; }
private boolean isPrimitive(Class<?> clazz){ boolean isPrimitiveOrWrapped = clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null; return isPrimitiveOrWrapped; }
private boolean isOfSameNumberType(Class<?> clazz,Class<?> fieldType){ if (isNumberType(clazz) && isNumberType(fieldType)){ if (ClassUtils.wrapperToPrimitive(clazz)!=null){ clazz = ClassUtils.wrapperToPrimitive(clazz); } if (ClassUtils.wrapperToPrimitive(fieldType)!=null){ fieldType = ClassUtils.wrapperToPrimitive(fieldType); } if (clazz==fieldType){ return true; } } return false; }
/** * Determines if the given object is a primitive or a wrapper to a primitive. Note, even though a * <code>String</code> may not be a primitive in the traditional sense, but it is considered one * here as it is <i>not</i> a struct. * * @param clazz input class * @return true, if the object is a primitive or a wrapper to a primitive, false otherwise. * */ private boolean isPrimitive(Class<?> clazz) { return clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null || clazz.getSimpleName().equals("String"); } }
/** * 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 */ protected boolean isScalarValue(Object value) { return ClassUtils.wrapperToPrimitive(value.getClass()) != null; }
/** * 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 */ protected boolean isScalarValue(Object value) { return ClassUtils.wrapperToPrimitive(value.getClass()) != null; }
private boolean isOfSameNumberType(Class<?> clazz,Class<?> fieldType){ if (isNumberType(clazz) && isNumberType(fieldType)){ if (ClassUtils.wrapperToPrimitive(clazz)!=null){ clazz = ClassUtils.wrapperToPrimitive(clazz); } if (ClassUtils.wrapperToPrimitive(fieldType)!=null){ fieldType = ClassUtils.wrapperToPrimitive(fieldType); } if (clazz==fieldType){ return true; } } return false; }
/** * Determines if the given object is a primitive or a wrapper to a primitive. Note, even though a * <code>String</code> may not be a primitive in the traditional sense, but it is considered one * here as it is <i>not</i> a struct. * * @param clazz input class * @return true, if the object is a primitive or a wrapper to a primitive, false otherwise. * */ private boolean isPrimitive(Class<?> clazz) { return clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null || clazz.getSimpleName().equals("String"); } }
/** * Determines if the given object is a primitive or a wrapper to a primitive. Note, even though a * <code>String</code> may not be a primitive in the traditional sense, but it is considered one * here as it is <i>not</i> a struct. * * @param clazz input class * @return true, if the object is a primitive or a wrapper to a primitive, false otherwise. * */ private boolean isPrimitive(Class<?> clazz) { return clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null || clazz.getSimpleName().equals("String"); } }
private boolean validate(Object instance, Class<?>[] inputTypes) { boolean validation = true; for (Class<?> cls : inputTypes) { if (!(cls.isPrimitive() || ClassUtils.wrapperToPrimitive(cls) != null || cls.isAssignableFrom(String.class))) { validation = false; log.error("Only primitives or String parameter types are supported for persistent jobs. '{}' is not supported", cls.getSimpleName()); } } return validation; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }