// Path: src/main/java/org/vaadin/easybinder/data/converters/NullConverter.java
// @SuppressWarnings("serial")
// public class NullConverter<T> implements Converter<T, T> {
// 
// 	protected T nullRepresentation;
// 
// 	public NullConverter(T nullRepresentation) {
// 		this.nullRepresentation = nullRepresentation;
// 	}
// 
// 	@Override
// 	public Result<T> convertToModel(T value, ValueContext context) {
// 		return (nullRepresentation == null && value == null)
// 				|| (nullRepresentation != null && nullRepresentation.equals(value)) ? Result.ok(null)
// 						: Result.ok(value);
// 	}
// 
// 	@Override
// 	public T convertToPresentation(T value, ValueContext context) {
// 		return value == null ? nullRepresentation : value;
// 	}
// }
// 
// Path: src/main/java/org/vaadin/easybinder/data/converters/StringLengthConverterValidator.java
// public class StringLengthConverterValidator implements Converter<String, String> {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	Integer minLength;
// 	Integer maxLength;
// 	String errorMessage;
// 
// 	public StringLengthConverterValidator(String errorMessage, Integer minLength, Integer maxLength) {
// 		this.errorMessage = errorMessage;
// 		this.minLength = minLength;
// 		this.maxLength = maxLength;
// 	}
// 
// 	@Override
// 	public Result<String> convertToModel(String value, ValueContext context) {
// 		if (value == null) {
// 			return Result.ok(null);
// 		}
// 		if (minLength != null && value.length() < minLength || maxLength != null && value.length() > maxLength) {
// 			return Result.error(errorMessage);
// 		}
// 		return Result.ok(value);
// 	}
// 
// 	@Override
// 	public String convertToPresentation(String value, ValueContext context) {
// 		return value;
// 	}
// 
// }


import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.vaadin.easybinder.data.converters.NullConverter;
import org.vaadin.easybinder.data.converters.StringLengthConverterValidator;
import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.converter.LocalDateTimeToDateConverter;
import com.vaadin.data.converter.LocalDateToDateConverter;
import com.vaadin.data.converter.StringToBigDecimalConverter;
import com.vaadin.data.converter.StringToBigIntegerConverter;
import com.vaadin.data.converter.StringToBooleanConverter;
import com.vaadin.data.converter.StringToDoubleConverter;
import com.vaadin.data.converter.StringToFloatConverter;
import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.converter.StringToLongConverter;
/*
 * Copyright 2017 Lars Sønderby Jessen
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.vaadin.easybinder.data;




public class ConverterRegistry {
	static ConverterRegistry instance;

	protected Map<Pair<Class<?>, Class<?>>, Converter<?, ?>> converters = new HashMap<>();

	public static ConverterRegistry getInstance() {
		if (instance == null) {
			instance = new ConverterRegistry();
		}
		return instance;
	}

	@SuppressWarnings("unchecked")
	private ConverterRegistry() {

		registerConverter(String.class, int.class, new StringLengthConverterValidator("Must be a number", 1, null)
				.chain(new StringToIntegerConverter("Must be a number")));
		registerConverter(String.class, Integer.class,
// Path: src/main/java/org/vaadin/easybinder/data/converters/NullConverter.java
// @SuppressWarnings("serial")
// public class NullConverter<T> implements Converter<T, T> {
// 
// 	protected T nullRepresentation;
// 
// 	public NullConverter(T nullRepresentation) {
// 		this.nullRepresentation = nullRepresentation;
// 	}
// 
// 	@Override
// 	public Result<T> convertToModel(T value, ValueContext context) {
// 		return (nullRepresentation == null && value == null)
// 				|| (nullRepresentation != null && nullRepresentation.equals(value)) ? Result.ok(null)
// 						: Result.ok(value);
// 	}
// 
// 	@Override
// 	public T convertToPresentation(T value, ValueContext context) {
// 		return value == null ? nullRepresentation : value;
// 	}
// }
// 
// Path: src/main/java/org/vaadin/easybinder/data/converters/StringLengthConverterValidator.java
// public class StringLengthConverterValidator implements Converter<String, String> {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	Integer minLength;
// 	Integer maxLength;
// 	String errorMessage;
// 
// 	public StringLengthConverterValidator(String errorMessage, Integer minLength, Integer maxLength) {
// 		this.errorMessage = errorMessage;
// 		this.minLength = minLength;
// 		this.maxLength = maxLength;
// 	}
// 
// 	@Override
// 	public Result<String> convertToModel(String value, ValueContext context) {
// 		if (value == null) {
// 			return Result.ok(null);
// 		}
// 		if (minLength != null && value.length() < minLength || maxLength != null && value.length() > maxLength) {
// 			return Result.error(errorMessage);
// 		}
// 		return Result.ok(value);
// 	}
// 
// 	@Override
// 	public String convertToPresentation(String value, ValueContext context) {
// 		return value;
// 	}
// 
// }


// Path: src/main/java/org/vaadin/easybinder/data/ConverterRegistry.java
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.vaadin.easybinder.data.converters.NullConverter;
import org.vaadin.easybinder.data.converters.StringLengthConverterValidator;
import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.converter.LocalDateTimeToDateConverter;
import com.vaadin.data.converter.LocalDateToDateConverter;
import com.vaadin.data.converter.StringToBigDecimalConverter;
import com.vaadin.data.converter.StringToBigIntegerConverter;
import com.vaadin.data.converter.StringToBooleanConverter;
import com.vaadin.data.converter.StringToDoubleConverter;
import com.vaadin.data.converter.StringToFloatConverter;
import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.converter.StringToLongConverter;

/*
 * Copyright 2017 Lars Sønderby Jessen
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.vaadin.easybinder.data;




public class ConverterRegistry {
	static ConverterRegistry instance;

	protected Map<Pair<Class<?>, Class<?>>, Converter<?, ?>> converters = new HashMap<>();

	public static ConverterRegistry getInstance() {
		if (instance == null) {
			instance = new ConverterRegistry();
		}
		return instance;
	}

	@SuppressWarnings("unchecked")
	private ConverterRegistry() {

		registerConverter(String.class, int.class, new StringLengthConverterValidator("Must be a number", 1, null)
				.chain(new StringToIntegerConverter("Must be a number")));
		registerConverter(String.class, Integer.class,
				new NullConverter<String>("").chain(new StringToIntegerConverter("Must be a number")));