1 16 17 package org.apache.commons.beanutils.locale.converters; 18 19 import org.apache.commons.beanutils.ConversionException; 20 21 import java.util.Locale ; 22 import java.text.ParseException ; 23 24 25 35 36 public class FloatLocaleConverter extends DecimalLocaleConverter { 37 38 39 41 49 public FloatLocaleConverter() { 50 51 this(false); 52 } 53 54 62 public FloatLocaleConverter(boolean locPattern) { 63 64 this(Locale.getDefault(), locPattern); 65 } 66 67 74 public FloatLocaleConverter(Locale locale) { 75 76 this(locale, false); 77 } 78 79 87 public FloatLocaleConverter(Locale locale, boolean locPattern) { 88 89 this(locale, (String ) null, locPattern); 90 } 91 92 100 public FloatLocaleConverter(Locale locale, String pattern) { 101 102 this(locale, pattern, false); 103 } 104 105 114 public FloatLocaleConverter(Locale locale, String pattern, boolean locPattern) { 115 116 super(locale, pattern, locPattern); 117 } 118 119 128 public FloatLocaleConverter(Object defaultValue) { 129 130 this(defaultValue, false); 131 } 132 133 142 public FloatLocaleConverter(Object defaultValue, boolean locPattern) { 143 144 this(defaultValue, Locale.getDefault(), locPattern); 145 } 146 147 155 public FloatLocaleConverter(Object defaultValue, Locale locale) { 156 157 this(defaultValue, locale, false); 158 } 159 160 169 public FloatLocaleConverter(Object defaultValue, Locale locale, boolean locPattern) { 170 171 this(defaultValue, locale, null, locPattern); 172 } 173 174 183 public FloatLocaleConverter(Object defaultValue, Locale locale, String pattern) { 184 185 this(defaultValue, locale, pattern, false); 186 } 187 188 198 public FloatLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern) { 199 200 super(defaultValue, locale, pattern); 201 } 202 203 214 protected Object parse(Object value, String pattern) throws ParseException { 215 final Number parsed = (Number ) super.parse(value, pattern); 216 if( Math.abs(parsed.doubleValue() - parsed.floatValue()) > parsed.floatValue() * 0.00001 ) { 217 throw new ConversionException("Suplied number is not of type Float: "+parsed.longValue()); 218 } 219 return new Float (parsed.floatValue()); } 221 } 222 | Popular Tags |