Warning: session_start(): open(/var/lib/php/sessions/sess_a333s9s67ckenm4ebg4vu3rsb6, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// Can a be converted to b?
// score 0 = exact match
// score Int.MAX_VALUE = no match
// score 1 = conversion needed (boxing/unboxing or non-primitve widening)
// score -2 = primitive widening needed
static int typeConversionScore(Class a, Class b) {
if (a == b) ret 0;
if (b.isPrimitive()) {
// target type is primitive
if (a.isPrimitive()) {
// both types are primitive
// No widenings to bool
if (b == bool.class) ret Int.MAX_VALUE;
// No widenings to byte
if (b == byte.class) ret Int.MAX_VALUE;
// byte can be converted to char
if (b == char.class) ret a == byte.class ? -2 : Int.MAX_VALUE;
// byte can be converted to short
if (b == short.class) ret a == byte.class ? -2 : Int.MAX_VALUE;
// byte, char and short can be converted to int
if (b == int.class) ret a == byte.class || a == char.class || a == short.class ? -2 : Int.MAX_VALUE;
// byte, char, short and int can be converted to long
if (b == long.class) ret a == byte.class || a == char.class || a == short.class || a == int.class ? -2 : Int.MAX_VALUE;
// byte, char, short and int can be converted to float
if (b == float.class) ret a == byte.class || a == char.class || a == short.class || a == int.class ? -2 : Int.MAX_VALUE;
// all primitive types except bool can be converted to double
ret a != bool.class ? -2 : Int.MAX_VALUE;
} else {
// source type is boxed - check if they're a match
ret primitiveToBoxedType(b) == a ? 1 : Int.MAX_VALUE;
}
} else {
// target type is not primitive
// object type is primitive - check for exact match
if (a.isPrimitive()) ret primitiveToBoxedType(a) == b ? 1 : Int.MAX_VALUE;
// both types are not primitive
ret b.isAssignableFrom(a) ? 1 : Int.MAX_VALUE;
}
}