/** * Set the Locale for the <i>Converter</i>. * * @param locale The locale to use for conversion */ public void setLocale(final Locale locale) { this.locale = locale; setUseLocaleFormat(true); }
/** * Set a date format pattern to use to convert * dates to/from a <code>java.lang.String</code>. * * @see SimpleDateFormat * @param pattern The format pattern. */ public void setPattern(final String pattern) { setPatterns(new String[] {pattern}); }
/** * Construct a <i>Converter</i> that returns a default * value if an error occurs. * * @param defaultValue The default value to be returned * if the value to be converted is missing or an error * occurs converting the value. */ public AbstractConverter(final Object defaultValue) { setDefaultValue(defaultValue); }
/** * Remove all registered {@link Converter}s, and re-establish the * standard Converters. */ public void deregister() { converters.clear(); registerPrimitives(false); registerStandard(false, false); registerOther(true); registerArrays(false, 0); register(BigDecimal.class, new BigDecimalConverter()); register(BigInteger.class, new BigIntegerConverter()); }
/** * Performs a conversion to the default type. This method is called if we do * not have a target class. In this case, the T parameter is not set. * Therefore, we can cast to it (which is required to fulfill the contract * of the method signature). * * @param <T> the type of the result object * @param targetClass the target class of the conversion * @param value the value to be converted * @return the converted value */ private <T> T convertToDefaultType(final Class<T> targetClass, final Object value) { @SuppressWarnings("unchecked") final T result = (T) convert(getDefaultType(), value); return result; }
/** * Set the Locale for the <i>Converter</i>. * * @param locale The Locale. */ public void setLocale(final Locale locale) { this.locale = locale; setUseLocaleFormat(true); }
/** * Construct a <code>java.lang.Number</code> <i>Converter</i> that returns * a default value if an error occurs. * * @param allowDecimals Indicates whether decimals are allowed * @param defaultValue The default value to be returned */ public NumberConverter(final boolean allowDecimals, final Object defaultValue) { super(); this.allowDecimals = allowDecimals; setDefaultValue(defaultValue); }
/** * Provide a String representation of this converter. * * @return A String representation of this converter */ @Override public String toString() { return toString(getClass()) + "[UseDefault=" + useDefault + "]"; }
/** * Create a {@link org.apache.commons.beanutils.Converter} that will return the specified default value * if a conversion error occurs, ie the string value being converted is * not one of the known true strings, nor one of the known false strings. * * @param defaultValue The default value to be returned if the value * being converted is not recognized. This value may be null, in which * case null will be returned on conversion failure. When non-null, it is * expected that this value will be either Boolean.TRUE or Boolean.FALSE. * The special value BooleanConverter.NO_DEFAULT can also be passed here, * in which case this constructor acts like the no-argument one. */ public BooleanConverter(final Object defaultValue) { super(); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue); } }
/** strictly for convenience since it has same parameter order as Map.put */ private void register(final Class<?> clazz, final Converter converter) { register(new ConverterFacade(converter), clazz); }
/** * Remove all registered {@link Converter}s, and re-establish the * standard Converters. */ public void deregister() { converters.clear(); registerPrimitives(false); registerStandard(false, false); registerOther(true); registerArrays(false, 0); register(BigDecimal.class, new BigDecimalConverter()); register(BigInteger.class, new BigIntegerConverter()); }
/** * Performs a conversion to the default type. This method is called if we do * not have a target class. In this case, the T parameter is not set. * Therefore, we can cast to it (which is required to fulfill the contract * of the method signature). * * @param <T> the type of the result object * @param targetClass the target class of the conversion * @param value the value to be converted * @return the converted value */ private <T> T convertToDefaultType(final Class<T> targetClass, final Object value) { @SuppressWarnings("unchecked") final T result = (T) convert(getDefaultType(), value); return result; }
/** * Set a number format pattern to use to convert * Numbers to/from a <code>java.lang.String</code>. * <p> * See <code>java.text.DecimalFormat</code> for details * of how to specify the pattern. * * @param pattern The format pattern. */ public void setPattern(final String pattern) { this.pattern = pattern; setUseLocaleFormat(true); }
/** * Set a date format pattern to use to convert * dates to/from a <code>java.lang.String</code>. * * @see SimpleDateFormat * @param pattern The format pattern. */ public void setPattern(final String pattern) { setPatterns(new String[] {pattern}); }
/** * Construct a <i>Converter</i> that returns a default * value if an error occurs. * * @param defaultValue The default value to be returned * if the value to be converted is missing or an error * occurs converting the value. */ public AbstractConverter(final Object defaultValue) { setDefaultValue(defaultValue); }
/** * Set the Locale for the <i>Converter</i>. * * @param locale The Locale. */ public void setLocale(final Locale locale) { this.locale = locale; setUseLocaleFormat(true); }
/** * Construct a <code>java.lang.Number</code> <i>Converter</i> that returns * a default value if an error occurs. * * @param allowDecimals Indicates whether decimals are allowed * @param defaultValue The default value to be returned */ public NumberConverter(final boolean allowDecimals, final Object defaultValue) { super(); this.allowDecimals = allowDecimals; setDefaultValue(defaultValue); }
/** * Provide a String representation of this converter. * * @return A String representation of this converter */ @Override public String toString() { return toString(getClass()) + "[UseDefault=" + useDefault + "]"; }
/** * Set the Locale for the <i>Converter</i>. * * @param locale The locale to use for conversion */ public void setLocale(final Locale locale) { this.locale = locale; setUseLocaleFormat(true); }
/** * Set a number format pattern to use to convert * Numbers to/from a <code>java.lang.String</code>. * <p> * See <code>java.text.DecimalFormat</code> for details * of how to specify the pattern. * * @param pattern The format pattern. */ public void setPattern(final String pattern) { this.pattern = pattern; setUseLocaleFormat(true); }