/** * <p>Converts the specified array of primitive Class objects to an array of * its corresponding wrapper Class objects.</p> * * @param classes the class array to convert, may be null or empty * @return an array which contains for each given class, the wrapper class or * the original class if class is not a primitive. <code>null</code> if null input. * Empty array if an empty array passed in. * @since 2.1 */ public static Class[] primitivesToWrappers(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] = primitiveToWrapper(classes[i]); } return convertedClasses; }
cls = primitiveToWrapper(cls); if (cls == null) { return false;
public UpdateQuerier(DataAccessFactory dataAccessFactory, StatementMetaData metaData) { this.dataAccessFactory = dataAccessFactory; // 转换基本类型 Class<?> returnType = metaData.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; this.returnGeneratedKeys = metaData.getReturnGeneratedKeys(); }
Class<?> returnType = statementMetaData.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType);
rowType = ClassUtils.primitiveToWrapper(rowType);
public CustomConverterDescription getCustomConverter(Class<?> srcClass, Class<?> destClass) { if (converters.isEmpty()) { return null; } // Let's see if the incoming class is a primitive: final Class<?> src = ClassUtils.primitiveToWrapper(srcClass); final Class<?> dest = ClassUtils.primitiveToWrapper(destClass); return findConverter(src, dest); }
public CustomConverterDescription getCustomConverter(Class<?> srcClass, Class<?> destClass) { if (converters.isEmpty()) { return null; } // Let's see if the incoming class is a primitive: final Class<?> src = ClassUtils.primitiveToWrapper(srcClass); final Class<?> dest = ClassUtils.primitiveToWrapper(destClass); return findConverter(src, dest); }
public static <T> boolean isTypeCompliant(@Nullable T value, @Nullable Class<?> expectedClass) { if (value == null || expectedClass == null) { return true; } Class<?> wrapped = ClassUtils.primitiveToWrapper(expectedClass); return wrapped.isAssignableFrom(((Object) value).getClass()); // auto-boxing of primitive types // TODO PolyString vs String - should be treated here? // TODO int vs long vs ... }
@SuppressWarnings("unchecked") private static Object getParamDefaultValue(PyObject pyObject, Class<?> parameterType) throws Exception { if (parameterType.equals(PyType.class)) { return pyObject.getType(); } else if (parameterType.isPrimitive()) { return ClassUtils.primitiveToWrapper(parameterType).getConstructor(String.class).newInstance("0"); } else if (Number.class.isAssignableFrom(parameterType) || String.class.isAssignableFrom(parameterType)) { return parameterType.getConstructor(String.class).newInstance("0"); } else { return null; } }
@SuppressWarnings("unchecked") private static Object getParamDefaultValue(PyObject pyObject, Class<?> parameterType) throws Exception { if (parameterType.equals(PyType.class)) { return pyObject.getType(); } else if (parameterType.isPrimitive()) { return ClassUtils.primitiveToWrapper(parameterType).getConstructor(String.class).newInstance("0"); } else if (Number.class.isAssignableFrom(parameterType) || String.class.isAssignableFrom(parameterType)) { return parameterType.getConstructor(String.class).newInstance("0"); } else { return null; } }
public PrimitiveTypeConverter(Class<T> primitiveClass) { Validate.notNull(primitiveClass); Validate.isTrue(primitiveClass.isPrimitive(), "The class [" + primitiveClass + "] is not a primitive class."); @SuppressWarnings("unchecked") final Class<T> wrapperClass = ClassUtils.primitiveToWrapper(primitiveClass); this.sourceClass = wrapperClass; this.destinationClass = primitiveClass; }
/** * TODO: decide if this method should be marked @NotNull. * Basically the problem is with primitives. When parsed, they sometimes return null. The question is if it's correct. */ <T> T unmarshal(@NotNull XNodeImpl xnode, @NotNull Class<T> beanClass, @NotNull ParsingContext pc) throws SchemaException { T value = unmarshalInternal(xnode, beanClass, pc); if (PrismContextImpl.isExtraValidation() && value != null) { Class<?> requested = ClassUtils.primitiveToWrapper(beanClass); Class<?> actual = ClassUtils.primitiveToWrapper(value.getClass()); if (!requested.isAssignableFrom(actual)) { throw new AssertionError("Postcondition fail: unmarshal returned a value of " + value + " (" + actual + ") which is not of requested type (" + requested + ")"); } } return value; }
public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) { this.dataAccessProvider = dataAccessProvider; Method method = metaData.getMethod(); // 转换基本类型 Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; if (returnType != void.class && (method.isAnnotationPresent(ReturnGeneratedKeys.class))) { returnGeneratedKeys = true; } else { returnGeneratedKeys = false; } }
public UpdateQuerier(DataAccessFactory dataAccessProvider, StatementMetaData metaData) { this.dataAccessProvider = dataAccessProvider; Method method = metaData.getMethod(); // 转换基本类型 Class<?> returnType = method.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } this.returnType = returnType; if (returnType == Identity.class || (returnType != void.class && (method .isAnnotationPresent(ReturnGeneratedKeys.class)))) { returnGeneratedKeys = true; } else { returnGeneratedKeys = false; } }
private CustomConverterDescription findConverter(Class<?> src, Class<?> dest) { // Otherwise, loop through custom converters and look for a match. // for (CustomConverterDescription customConverter : converters) { final Class<?> classA = ClassUtils.primitiveToWrapper(customConverter.getClassA()); final Class<?> classB = ClassUtils.primitiveToWrapper(customConverter.getClassB()); // we check to see if the destination class is the same as classA // defined in the converter mapping xml. // we next check if the source class is the same as classA defined // in the converter mapping xml. // we also to check to see if it is assignable to either. We then // perform these checks in the other direction for classB if ((classA.isAssignableFrom(dest) && classB.isAssignableFrom(src)) || (classA .isAssignableFrom(src) && classB.isAssignableFrom(dest))) { return customConverter; } } return null; }
@Override @SuppressWarnings("unchecked") public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { Object value; try { value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()), prefix + key); } catch (ConversionException cause) { throw cause; } return value; }
/** * {@inheritDoc} */ public Object convert(final Object source, final TypeDescriptor sourceType, final TypeDescriptor targetType) { if (source == null) { return null; } Class<?> type = targetType.getType(); if (type.isPrimitive()) { type = ClassUtils.primitiveToWrapper(type); } if (type.isAssignableFrom(source.getClass())) { return source; } return beanMapper.map(source, type); }
protected boolean matches(JCodeModel codeModel, JType type, Class theClass) { final JType classType; if (Void.TYPE.equals(theClass)) { return codeModel.VOID.equals(type); } else if (theClass.isPrimitive()) { Class wrapperClass = org.apache.commons.lang.ClassUtils.primitiveToWrapper(theClass); classType = codeModel.ref(wrapperClass).getPrimitiveType(); } else { classType = codeModel.ref(theClass); } return type.equals(classType); }
private static Object nullToPrimitive(Class targetType) { if (targetType == boolean.class) { return false; } if (targetType == char.class) { return (char) 0; } Class wrapper = ClassUtils.primitiveToWrapper(targetType); Constructor c = BeanClassUtils.safeGetConstructor(wrapper, strType); return BeanClassUtils.createInstance(wrapper, c, ZERO); } }
private Converter getPrimitiveOrWrapperConverter(Class destClass, DateFormatContainer dateFormatContainer) { if (String.class.equals(destClass)) { return new StringConverter(dateFormatContainer); } Converter result = CONVERTER_MAP.get(ClassUtils.primitiveToWrapper(destClass)); if (result == null) { if (java.util.Date.class.isAssignableFrom(destClass)) { result = new DateConverter(dateFormatContainer.getDateFormat()); } else if (Calendar.class.isAssignableFrom(destClass)) { result = new CalendarConverter(dateFormatContainer.getDateFormat()); } else if (XMLGregorianCalendar.class.isAssignableFrom(destClass)) { result = new XMLGregorianCalendarConverter(dateFormatContainer.getDateFormat()); } } return result == null ? new StringConstructorConverter(dateFormatContainer) : result; }