/** * Sets the default value for Boolean conversions. * @param newDefaultBoolean The default Boolean value * @deprecated Register replacement converters for Boolean.TYPE and * Boolean.class instead */ @Deprecated public void setDefaultBoolean(final boolean newDefaultBoolean) { defaultBoolean = (newDefaultBoolean ? Boolean.TRUE : Boolean.FALSE); register(new BooleanConverter(defaultBoolean), Boolean.TYPE); register(new BooleanConverter(defaultBoolean), Boolean.class); }
for (int i = 0; i < values.length; i++) { final String stringValue = values[i]; final Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue(); for (int i = 0; i < results.length; i++) { final String stringValue = (String) list.get(i); final Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue();
final Object defaultValue) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue);
public static Boolean toBoolean(Object input, boolean defaultValue) { if (input == null) return defaultValue; if (input instanceof Boolean) return (Boolean) input; BooleanConverter booleanConverter = new BooleanConverter(defaultValue); return booleanConverter.convert(null, input); }
/** * 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); } }
/** * Create a {@link org.apache.commons.beanutils.Converter} that will throw a * {@link org.apache.commons.beanutils.ConversionException} * 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. * <p> * The provided string arrays are copied, so that changes to the elements * of the array after this call is made do not affect this object. * * @param trueStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * * @param falseStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * @since 1.8.0 */ public BooleanConverter(final String[] trueStrings, final String[] falseStrings) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); }
throw conversionException(type, value);
/** * 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); } }
/** * Create a {@link org.apache.commons.beanutils.Converter} that will throw a * {@link org.apache.commons.beanutils.ConversionException} * 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. * <p> * The provided string arrays are copied, so that changes to the elements * of the array after this call is made do not affect this object. * * @param trueStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * * @param falseStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * @since 1.8.0 */ public BooleanConverter(final String[] trueStrings, final String[] falseStrings) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); }
throw conversionException(type, value);
/** * Sets the default value for Boolean conversions. * @param newDefaultBoolean The default Boolean value * @deprecated Register replacement converters for Boolean.TYPE and * Boolean.class instead */ @Deprecated public void setDefaultBoolean(final boolean newDefaultBoolean) { defaultBoolean = (newDefaultBoolean ? Boolean.TRUE : Boolean.FALSE); register(new BooleanConverter(defaultBoolean), Boolean.TYPE); register(new BooleanConverter(defaultBoolean), Boolean.class); }
final Object defaultValue) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue);
for (int i = 0; i < values.length; i++) { final String stringValue = values[i]; final Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue(); for (int i = 0; i < results.length; i++) { final String stringValue = (String) list.get(i); final Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue();
/** * 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 recognised. 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(Object defaultValue) { super(); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue); } }
/** * Create a {@link org.apache.commons.beanutils.Converter} that will throw a {@link ConversionException} * 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. * <p> * The provided string arrays are copied, so that changes to the elements * of the array after this call is made do not affect this object. * * @param trueStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * * @param falseStrings is the set of strings which should convert to the * value Boolean.TRUE. The value null must not be present. Case is * ignored. * @since 1.8.0 */ public BooleanConverter(String[] trueStrings, String[] falseStrings) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); }
throw conversionException(type, value);
/** * Register the converters for primitive types. * </p> * This method registers the following converters: * <ul> * <li><code>Boolean.TYPE</code> - {@link BooleanConverter}</li> * <li><code>Byte.TYPE</code> - {@link ByteConverter}</li> * <li><code>Character.TYPE</code> - {@link CharacterConverter}</li> * <li><code>Double.TYPE</code> - {@link DoubleConverter}</li> * <li><code>Float.TYPE</code> - {@link FloatConverter}</li> * <li><code>Integer.TYPE</code> - {@link IntegerConverter}</li> * <li><code>Long.TYPE</code> - {@link LongConverter}</li> * <li><code>Short.TYPE</code> - {@link ShortConverter}</li> * </ul> * @param throwException <code>true</code> if the converters should * throw an exception when a conversion error occurs, otherwise <code> * <code>false</code> if a default value should be used. */ private void registerPrimitives(final boolean throwException) { register(Boolean.TYPE, throwException ? new BooleanConverter() : new BooleanConverter(Boolean.FALSE)); register(Byte.TYPE, throwException ? new ByteConverter() : new ByteConverter(ZERO)); register(Character.TYPE, throwException ? new CharacterConverter() : new CharacterConverter(SPACE)); register(Double.TYPE, throwException ? new DoubleConverter() : new DoubleConverter(ZERO)); register(Float.TYPE, throwException ? new FloatConverter() : new FloatConverter(ZERO)); register(Integer.TYPE, throwException ? new IntegerConverter() : new IntegerConverter(ZERO)); register(Long.TYPE, throwException ? new LongConverter() : new LongConverter(ZERO)); register(Short.TYPE, throwException ? new ShortConverter() : new ShortConverter(ZERO)); }
Object defaultValue) { super(); this.trueStrings = copyStrings(trueStrings); this.falseStrings = copyStrings(falseStrings); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue);
for (int i = 0; i < values.length; i++) { String stringValue = values[i]; Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue(); for (int i = 0; i < results.length; i++) { String stringValue = (String) list.get(i); Object result = booleanConverter.convert(Boolean.class, stringValue); results[i] = ((Boolean) result).booleanValue();
/** * 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 recognised. 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(Object defaultValue) { super(); if (defaultValue != NO_DEFAULT) { setDefaultValue(defaultValue); } }