HHH-16482 - Convert Functions in StandardConverters to static methods that can be used as method references

This commit is contained in:
Steve Ebersole 2023-04-18 04:51:42 -05:00
parent 85a636c856
commit d7c5db47f6
1 changed files with 12 additions and 6 deletions

View File

@ -15,7 +15,9 @@ import static org.hibernate.engine.config.spi.ConfigurationService.Converter;
* @author Steve Ebersole
*/
public class StandardConverters {
public static final Converter<Boolean> BOOLEAN = (value) -> {
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;
public static Boolean asBoolean(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
@ -23,17 +25,21 @@ public class StandardConverters {
return value instanceof Boolean
? (Boolean) value
: Boolean.parseBoolean( value.toString() );
};
}
public static final Converter<String> STRING = (value) -> {
public static final Converter<String> STRING = StandardConverters::asString;
public static String asString(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
return value.toString();
};
}
public static final Converter<Integer> INTEGER = (value) -> {
public static final Converter<Integer> INTEGER = StandardConverters::asInteger;
public static Integer asInteger(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
@ -43,7 +49,7 @@ public class StandardConverters {
}
return Integer.parseInt( value.toString() );
};
}
/**
* Disallow direct instantiation