mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 12:44:49 +00:00
HHH-16482 - Convert Functions in StandardConverters to static methods that can be used as method references
(cherry picked from commit d7c5db47f6ed912e5776a610791f0f55a322d5a5)
This commit is contained in:
parent
f5be9556d7
commit
9db89979bf
@ -15,7 +15,9 @@
|
|||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class StandardConverters {
|
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 ) {
|
if ( value == null ) {
|
||||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||||
}
|
}
|
||||||
@ -23,17 +25,21 @@ public class StandardConverters {
|
|||||||
return value instanceof Boolean
|
return value instanceof Boolean
|
||||||
? (Boolean) value
|
? (Boolean) value
|
||||||
: Boolean.parseBoolean( value.toString() );
|
: 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 ) {
|
if ( value == null ) {
|
||||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.toString();
|
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 ) {
|
if ( value == null ) {
|
||||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||||
}
|
}
|
||||||
@ -43,7 +49,7 @@ public class StandardConverters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Integer.parseInt( value.toString() );
|
return Integer.parseInt( value.toString() );
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disallow direct instantiation
|
* Disallow direct instantiation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user