/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * * @param type * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(final Class<?> type) { if (type == null) { return false; } return type.isPrimitive() || isPrimitiveWrapper(type); }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { buffer.append(ReflectionToStringBuilder.toString(value, this)); } else { super.appendDetail(buffer, fieldName, value); } }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { spaces += INDENT; resetIndent(); buffer.append(ReflectionToStringBuilder.toString(value, this)); spaces -= INDENT; resetIndent(); } else { super.appendDetail(buffer, fieldName, value); } }
@Test public void testIsPrimitiveWrapper() { // test primitive wrapper classes assertTrue("Boolean.class", ClassUtils.isPrimitiveWrapper(Boolean.class)); assertTrue("Byte.class", ClassUtils.isPrimitiveWrapper(Byte.class)); assertTrue("Character.class", ClassUtils.isPrimitiveWrapper(Character.class)); assertTrue("Short.class", ClassUtils.isPrimitiveWrapper(Short.class)); assertTrue("Integer.class", ClassUtils.isPrimitiveWrapper(Integer.class)); assertTrue("Long.class", ClassUtils.isPrimitiveWrapper(Long.class)); assertTrue("Double.class", ClassUtils.isPrimitiveWrapper(Double.class)); assertTrue("Float.class", ClassUtils.isPrimitiveWrapper(Float.class)); // test primitive classes assertFalse("boolean", ClassUtils.isPrimitiveWrapper(Boolean.TYPE)); assertFalse("byte", ClassUtils.isPrimitiveWrapper(Byte.TYPE)); assertFalse("char", ClassUtils.isPrimitiveWrapper(Character.TYPE)); assertFalse("short", ClassUtils.isPrimitiveWrapper(Short.TYPE)); assertFalse("int", ClassUtils.isPrimitiveWrapper(Integer.TYPE)); assertFalse("long", ClassUtils.isPrimitiveWrapper(Long.TYPE)); assertFalse("double", ClassUtils.isPrimitiveWrapper(Double.TYPE)); assertFalse("float", ClassUtils.isPrimitiveWrapper(Float.TYPE)); // others assertFalse("null", ClassUtils.isPrimitiveWrapper(null)); assertFalse("Void.class", ClassUtils.isPrimitiveWrapper(Void.class)); assertFalse("Void.TYPE", ClassUtils.isPrimitiveWrapper(Void.TYPE)); assertFalse("String.class", ClassUtils.isPrimitiveWrapper(String.class)); assertFalse("this.getClass()", ClassUtils.isPrimitiveWrapper(this.getClass())); }
@Override public String toString() { String tname; if (ClassUtils.isPrimitiveWrapper(getRawType())) { tname = ClassUtils.wrapperToPrimitive(getRawType()).getName(); } else { tname = type.toString(); } return "TypedName[" + name + ": " + tname + "]"; }
/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * * @param type * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(final Class<?> type) { if (type == null) { return false; } return type.isPrimitive() || isPrimitiveWrapper(type); }
/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * * @param type * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(final Class<?> type) { if (type == null) { return false; } return type.isPrimitive() || isPrimitiveWrapper(type); }
/** * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * * @param type * The class to query or null. * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character}, * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}). * @since 3.1 */ public static boolean isPrimitiveOrWrapper(final Class<?> type) { if (type == null) { return false; } return type.isPrimitive() || isPrimitiveWrapper(type); }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { buffer.append(ReflectionToStringBuilder.toString(value, this)); } else { super.appendDetail(buffer, fieldName, value); } }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { buffer.append(ReflectionToStringBuilder.toString(value, this)); } else { super.appendDetail(buffer, fieldName, value); } }
@Override @GwtIncompatible("incompatible method") public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { buffer.append(ReflectionToStringBuilder.toString(value, this)); } else { super.appendDetail(buffer, fieldName, value); } }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { spaces += INDENT; resetIndent(); buffer.append(ReflectionToStringBuilder.toString(value, this)); spaces -= INDENT; resetIndent(); } else { super.appendDetail(buffer, fieldName, value); } }
@Override public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { spaces += INDENT; resetIndent(); buffer.append(ReflectionToStringBuilder.toString(value, this)); spaces -= INDENT; resetIndent(); } else { super.appendDetail(buffer, fieldName, value); } }
&& !method.getReturnType().equals(String.class) && !method.getReturnType().isEnum() && !ClassUtils.isPrimitiveWrapper(method.getReturnType())) { return false;
@Override @GwtIncompatible("incompatible method") public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && !String.class.equals(value.getClass()) && accept(value.getClass())) { spaces += INDENT; resetIndent(); buffer.append(ReflectionToStringBuilder.toString(value, this)); spaces -= INDENT; resetIndent(); } else { super.appendDetail(buffer, fieldName, value); } }
/** * This helper method facilitates creation of Wrapper data type object and initialize it with the provided value. * * @param type * The type to instantiate. It has to be only a Wrapper data type [ such as Integer, Float, Boolean * etc.,] * @param objectToInvokeUpon * The object upon which the invocation is to be carried out. * @param valueToAssign * The value to initialize with. * @return An initialized object that represents the Wrapper data type. */ public static Object instantiateWrapperObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign) { logger.entering(new Object[] { type, objectToInvokeUpon, valueToAssign }); validateParams(type, objectToInvokeUpon, valueToAssign); checkArgument(ClassUtils.isPrimitiveWrapper(type), type.getName() + " is NOT a wrapper data type."); try { Object objectToReturn = type.getConstructor(new Class<?>[] { String.class }).newInstance(valueToAssign); logger.exiting(objectToInvokeUpon); return objectToReturn; } catch (InstantiationException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new ReflectionException(e); } }
@Override public String toString() { String tname; if (ClassUtils.isPrimitiveWrapper(getRawType())) { tname = ClassUtils.wrapperToPrimitive(getRawType()).getName(); } else { tname = type.toString(); } return "TypedName[" + name + ": " + tname + "]"; }
/** * This helper method facilitates creation of Wrapper data type object and initialize it with the provided value. * * @param type * The type to instantiate. It has to be only a Wrapper data type [ such as Integer, Float, Boolean * etc.,] * @param objectToInvokeUpon * The object upon which the invocation is to be carried out. * @param valueToAssign * The value to initialize with. * @return An initialized object that represents the Wrapper data type. */ public static Object instantiateWrapperObject(Class<?> type, Object objectToInvokeUpon, String valueToAssign) { logger.entering(new Object[] { type, objectToInvokeUpon, valueToAssign }); validateParams(type, objectToInvokeUpon, valueToAssign); checkArgument(ClassUtils.isPrimitiveWrapper(type), type.getName() + " is NOT a wrapper data type."); try { Object objectToReturn = type.getConstructor(new Class<?>[] { String.class }).newInstance(valueToAssign); logger.exiting(objectToInvokeUpon); return objectToReturn; } catch (InstantiationException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new ReflectionException(e); } }
@Override public void to(@Nullable T instance) { if (instance == null) { toNull(); return; } else if (!(instance instanceof Number) && !ClassUtils.isPrimitiveWrapper(instance.getClass()) && !sourceType.isInstance(instance)) { String msg = String.format("%s is not an instance of %s", instance, sourceType); throw new InvalidBindingException(sourceType, msg); } // Apply some type coercing if we're dealing with primitive types Object coerced = coerce(instance); Satisfaction s = Satisfactions.instance(coerced); BindRuleBuilder brb = startRule().setSatisfaction(s); generateBindings(brb, coerced.getClass()); }
if (!ClassUtils.isPrimitiveWrapper(fieldType) && Number.class.isAssignableFrom(ClassUtils.primitiveToWrapper(fieldType))) { final Number num = (Number) definedValue;