polish
This commit is contained in:
parent
31441627de
commit
3ef485bbbe
|
|
@ -21,12 +21,10 @@ package org.springframework.core.convert.converter;
|
||||||
*
|
*
|
||||||
* Implementing this interface is required when registering converters that do not declare their
|
* Implementing this interface is required when registering converters that do not declare their
|
||||||
* parameterized types S and T with a {@link org.springframework.core.convert.ConversionService}.
|
* parameterized types S and T with a {@link org.springframework.core.convert.ConversionService}.
|
||||||
* Such Converters are often dynamically created by a {@link ConverterFactory}.
|
|
||||||
*
|
*
|
||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @see Converter
|
* @see Converter
|
||||||
* @see ConverterFactory
|
|
||||||
*/
|
*/
|
||||||
public interface ConverterInfo {
|
public interface ConverterInfo {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ import org.springframework.core.convert.converter.Converter;
|
||||||
class StringToCharacterConverter implements Converter<String, Character> {
|
class StringToCharacterConverter implements Converter<String, Character> {
|
||||||
|
|
||||||
public Character convert(String source) {
|
public Character convert(String source) {
|
||||||
if (source.length() == 0) {
|
if ("".equals(source)) {
|
||||||
throw new IllegalArgumentException("Invalid value; to convert to a Character a String must have a length of 1 or greater");
|
return null;
|
||||||
}
|
}
|
||||||
return source.charAt(0);
|
return source.charAt(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.core.convert.support;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.core.convert.converter.ConverterFactory;
|
import org.springframework.core.convert.converter.ConverterFactory;
|
||||||
import org.springframework.core.convert.converter.ConverterInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory for String to enum converters.
|
* A factory for String to enum converters.
|
||||||
|
|
@ -33,7 +32,7 @@ class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
|
||||||
return new StringToEnum(targetType);
|
return new StringToEnum(targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class StringToEnum<T extends Enum> implements Converter<String, T>, ConverterInfo {
|
private class StringToEnum<T extends Enum> implements Converter<String, T> {
|
||||||
|
|
||||||
private final Class<T> enumType;
|
private final Class<T> enumType;
|
||||||
|
|
||||||
|
|
@ -41,14 +40,6 @@ class StringToEnumConverterFactory implements ConverterFactory<String, Enum> {
|
||||||
this.enumType = enumType;
|
this.enumType = enumType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<String> getSourceType() {
|
|
||||||
return String.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<T> getTargetType() {
|
|
||||||
return this.enumType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T convert(String source) {
|
public T convert(String source) {
|
||||||
if ("".equals(source)) {
|
if ("".equals(source)) {
|
||||||
// It's an empty enum identifier: reset the enum value to null.
|
// It's an empty enum identifier: reset the enum value to null.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue