diff options
author | Anna Miroshnik <anna.miroshnik@arcadia.spb.ru> | 2014-12-04 15:52:27 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-12-08 19:14:31 +0000 |
commit | a28d6c2098e738dfd78e1df929ce689a2ceb6c2a (patch) | |
tree | 9b9e725043d4e6ad3d6f25ee5a28e4e8bf533bab /server/src | |
parent | bf4e325ac6387cac0afc8096b3ca65b88bf9fdfd (diff) | |
download | vaadin-framework-a28d6c2098e738dfd78e1df929ce689a2ceb6c2a.tar.gz vaadin-framework-a28d6c2098e738dfd78e1df929ce689a2ceb6c2a.zip |
Add new StringTo<Byte, Short, BigInteger> Converters (#14583)
DefaultConverterFactory was updated, added missed types.
Change-Id: I65cffc7f91df6f40e132b45e325e15f029f9848c
Diffstat (limited to 'server/src')
5 files changed, 18 insertions, 5 deletions
diff --git a/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java b/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java index 9054f258c7..81f1a85f89 100644 --- a/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java +++ b/server/src/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java @@ -88,6 +88,7 @@ public abstract class AbstractStringToNumberConverter<T> implements // Convert "" to null return null; } + return parsedValue; } diff --git a/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java b/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java index 26613c5d02..3a1f1a4252 100644 --- a/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java +++ b/server/src/com/vaadin/data/util/converter/DefaultConverterFactory.java @@ -17,6 +17,7 @@ package com.vaadin.data.util.converter; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Date; import java.util.logging.Logger; @@ -112,6 +113,12 @@ public class DefaultConverterFactory implements ConverterFactory { return new StringToDateConverter(); } else if (Enum.class.isAssignableFrom(sourceType)) { return new StringToEnumConverter(); + } else if (BigInteger.class.isAssignableFrom(sourceType)) { + return new StringToBigIntegerConverter(); + } else if (Short.class.isAssignableFrom(sourceType)) { + return new StringToShortConverter(); + } else if (Byte.class.isAssignableFrom(sourceType)) { + return new StringToByteConverter(); } else { return null; } diff --git a/server/src/com/vaadin/data/util/converter/StringToBigIntegerConverter.java b/server/src/com/vaadin/data/util/converter/StringToBigIntegerConverter.java index 1e830c1fd2..d176ac2e0d 100644 --- a/server/src/com/vaadin/data/util/converter/StringToBigIntegerConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToBigIntegerConverter.java @@ -15,6 +15,7 @@ */ package com.vaadin.data.util.converter; +import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -32,7 +33,7 @@ import java.util.Locale; * </p> * * @author Vaadin Ltd - * @since 7.3.1 + * @since */ public class StringToBigIntegerConverter extends AbstractStringToNumberConverter<BigInteger> { @@ -41,7 +42,7 @@ public class StringToBigIntegerConverter extends protected NumberFormat getFormat(Locale locale) { NumberFormat numberFormat = super.getFormat(locale); if (numberFormat instanceof DecimalFormat) { - ((DecimalFormat) numberFormat).setParseIntegerOnly(true); + ((DecimalFormat) numberFormat).setParseBigDecimal(true); } return numberFormat; @@ -51,7 +52,11 @@ public class StringToBigIntegerConverter extends public BigInteger convertToModel(String value, Class<? extends BigInteger> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { - return (BigInteger) convertToNumber(value, BigInteger.class, locale); + + BigDecimal bigDecimalValue = (BigDecimal) convertToNumber(value, + BigDecimal.class, locale); + + return (bigDecimalValue != null) ? bigDecimalValue.toBigInteger() : null; } @Override diff --git a/server/src/com/vaadin/data/util/converter/StringToByteConverter.java b/server/src/com/vaadin/data/util/converter/StringToByteConverter.java index b14182dc3f..26f52d108a 100644 --- a/server/src/com/vaadin/data/util/converter/StringToByteConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToByteConverter.java @@ -28,7 +28,7 @@ import java.util.Locale; * </p> * * @author Vaadin Ltd - * @since 7.3.1 + * @since */ public class StringToByteConverter extends AbstractStringToNumberConverter<Byte> { diff --git a/server/src/com/vaadin/data/util/converter/StringToShortConverter.java b/server/src/com/vaadin/data/util/converter/StringToShortConverter.java index 3761d11227..4ee085286f 100644 --- a/server/src/com/vaadin/data/util/converter/StringToShortConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToShortConverter.java @@ -28,7 +28,7 @@ import java.util.Locale; * </p> * * @author Vaadin Ltd - * @since 7.3.1 + * @since */ public class StringToShortConverter extends AbstractStringToNumberConverter<Short> { |