Browse Source

Remove accidental dependency from new converters to old

Change-Id: I9cd9e691fb30063a914729d15011f5d50e19d8d4
tags/8.0.0.alpha1
Artur Signell 7 years ago
parent
commit
b565956a51

+ 3
- 7
server/src/main/java/com/vaadin/data/util/converter/AbstractStringToNumberConverter.java View File

import java.text.ParsePosition; import java.text.ParsePosition;
import java.util.Locale; import java.util.Locale;


import com.vaadin.v7.data.util.converter.LegacyConverter.ConversionException;

/** /**
* A converter that converts from the number type T to {@link String} and back. * A converter that converts from the number type T to {@link String} and back.
* Uses the given locale and {@link NumberFormat} for formatting and parsing. * Uses the given locale and {@link NumberFormat} for formatting and parsing.
* @param locale * @param locale
* The locale to use for conversion * The locale to use for conversion
* @return The converted value * @return The converted value
* @throws ConversionException
* If there was a problem converting the value
*/ */
protected Number convertToNumber(String value, Locale locale)
throws ConversionException {
protected Number convertToNumber(String value, Locale locale) {
if (value == null) { if (value == null) {
return null; return null;
} }
ParsePosition parsePosition = new ParsePosition(0); ParsePosition parsePosition = new ParsePosition(0);
Number parsedValue = getFormat(locale).parse(value, parsePosition); Number parsedValue = getFormat(locale).parse(value, parsePosition);
if (parsePosition.getIndex() != value.length()) { if (parsePosition.getIndex() != value.length()) {
throw new ConversionException("Could not convert '" + value + "'");
throw new IllegalArgumentException(
"Could not convert '" + value + "'");
} }


if (parsedValue == null) { if (parsedValue == null) {

+ 2
- 5
server/src/main/java/com/vaadin/data/util/converter/Converter.java View File

import java.util.function.Function; import java.util.function.Function;


import com.vaadin.data.Binder.Binding; import com.vaadin.data.Binder.Binding;
import com.vaadin.v7.data.util.converter.LegacyConverter.ConversionException;
import com.vaadin.data.Result; import com.vaadin.data.Result;


/** /**
return new Converter<P, M>() { return new Converter<P, M>() {


@Override @Override
public Result<M> convertToModel(P value, Locale locale)
throws ConversionException {
public Result<M> convertToModel(P value, Locale locale) {
return toModel.apply(value); return toModel.apply(value);
} }


@Override @Override
public P convertToPresentation(M value, Locale locale)
throws ConversionException {
public P convertToPresentation(M value, Locale locale) {
return toPresentation.apply(value); return toPresentation.apply(value);
} }
}; };

+ 1
- 3
server/src/main/java/com/vaadin/data/util/converter/StringToIntegerConverter.java View File

import java.util.Locale; import java.util.Locale;


import com.vaadin.data.Result; import com.vaadin.data.Result;
import com.vaadin.v7.data.util.converter.LegacyConverter.ConversionException;


/** /**
* A converter that converts from {@link String} to {@link Integer} and back. * A converter that converts from {@link String} to {@link Integer} and back.
} }


@Override @Override
public Result<Integer> convertToModel(String value, Locale locale)
throws ConversionException {
public Result<Integer> convertToModel(String value, Locale locale) {
Number n = convertToNumber(value, locale); Number n = convertToNumber(value, locale);


if (n == null) { if (n == null) {

Loading…
Cancel
Save