commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Benedict" <pbened...@apache.org>
Subject Re: svn commit: r555489 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
Date Thu, 12 Jul 2007 14:05:32 GMT
This is trivial, but supplied is spelled wrong. Needs two P's.

On 7/11/07, niallp@apache.org <niallp@apache.org> wrote:
>
> Author: niallp
> Date: Wed Jul 11 21:53:26 2007
> New Revision: 555489
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=555489
> Log:
> BEANUTILS-44 FloatLocaleConverter cannot parse negative values - reported
> by Paul Jenkins
>
> Modified:
>
>     jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
>
>     jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
>
> Modified:
> jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
> URL:
> http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java?view=diff&rev=555489&r1=555488&r2=555489
>
> ==============================================================================
> ---
> jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
> (original)
> +++
> jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverter.java
> Wed Jul 11 21:53:26 2007
> @@ -214,8 +214,10 @@
>      */
>     protected Object parse(Object value, String pattern) throws
> ParseException {
>        final Number parsed = (Number) super.parse(value, pattern);
> -      if( Math.abs(parsed.doubleValue() - parsed.floatValue()) >
> parsed.floatValue() * 0.00001 ) {
> -         throw new ConversionException("Suplied number is not of type
> Float: "+parsed.longValue());
> +      double doubleValue = parsed.doubleValue();
> +      double posDouble = (doubleValue >= (double)0) ? doubleValue :
> (doubleValue * (double)-1);
> +      if (posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE) {
> +          throw new ConversionException("Suplied number is not of type
> Float: "+parsed);
>        }
>        return new Float(parsed.floatValue()); // unlike superclass it
> returns Float type
>     }
>
> Modified:
> jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
> URL:
> http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java?view=diff&rev=555489&r1=555488&r2=555489
>
> ==============================================================================
> ---
> jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
> (original)
> +++
> jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTestCase.java
> Wed Jul 11 21:53:26 2007
> @@ -17,6 +17,8 @@
>
> package org.apache.commons.beanutils.locale.converters;
>
> +import java.text.DecimalFormat;
> +import org.apache.commons.beanutils.ConversionException;
>
> /**
>   * Test Case for the FloatLocaleConverter class.
> @@ -256,6 +258,49 @@
>          convertInvalid(converter, defaultValue);
>          convertNull(converter, defaultValue);
>
> +    }
> +
> +    /**
> +     * Test Float limits
> +     */
> +    public void testFloatLimits() {
> +
> +        converter = new FloatLocaleConverter(defaultLocale,
> defaultDecimalPattern);
> +        DecimalFormat fmt = new
> DecimalFormat("#.#############################################################");
> +
> +        assertEquals(new Float(-0.12), converter.convert("-0.12"));
> +        assertEquals("Positive Float.MAX_VALUE", new Float(
> Float.MAX_VALUE), converter.convert(fmt.format(Float.MAX_VALUE)));
> +        assertEquals("Positive Float.MIN_VALUE", new Float(
> Float.MIN_VALUE), converter.convert(fmt.format(Float.MIN_VALUE)));
> +
> +        assertEquals("Negative Float.MAX_VALUE", new Float(
> Float.MAX_VALUE * -1), converter.convert(fmt.format(Float.MAX_VALUE *
> -1)));
> +        assertEquals("Negative Float.MIN_VALUE", new Float(
> Float.MIN_VALUE * -1), converter.convert(fmt.format(Float.MIN_VALUE *
> -1)));
> +
> +
> +        try {
> +            converter.convert(fmt.format((double)Float.MAX_VALUE *
> (double)10));
> +            fail("Positive Too Large should throw ConversionException");
> +        } catch (ConversionException e) {
> +            // expected result
> +        }
> +        try {
> +            converter.convert(fmt.format((double)Float.MAX_VALUE *
> (double)-10));
> +            fail("Negative Too Large should throw ConversionException");
> +        } catch (ConversionException e) {
> +            // expected result
> +        }
> +
> +        try {
> +            converter.convert(fmt.format((double)Float.MIN_VALUE /
> (double)10));
> +            fail("Positive Too Small should throw ConversionException");
> +        } catch (ConversionException e) {
> +            // expected result
> +        }
> +        try {
> +            converter.convert(fmt.format((double)Float.MIN_VALUE /
> (double)-10));
> +            fail("Negative Too Small should throw ConversionException");
> +        } catch (ConversionException e) {
> +            // expected result
> +        }
>      }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message