public static Type unbox(Type type) { Primitive primitive = Primitive.ofBox(type); if (primitive != null) { return primitive.primitiveClass; } else { return type; } }
/** * Converts a boxed type to a primitive type; returns other types * unchanged. */ public static Type unbox(Type type) { Primitive primitive = ofBox(type); return primitive == null ? type : primitive.primitiveClass; }
/** * Converts a boxed class to a primitive class; returns other types * unchanged. */ public static Class unbox(Class type) { Primitive primitive = ofBox(type); return primitive == null ? type : primitive.primitiveClass; }
static boolean isA(Type fromType, Primitive primitive) { return Primitive.of(fromType) == primitive || Primitive.ofBox(fromType) == primitive; }
static boolean isA(Type fromType, Primitive primitive) { return Primitive.of(fromType) == primitive || Primitive.ofBox(fromType) == primitive; }
private Primitive javaPrimitive(RelDataType type) { if (type instanceof RelDataTypeFactoryImpl.JavaType) { return Primitive.ofBox( ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()); } return null; }
private Primitive javaPrimitive(RelDataType type) { if (type instanceof RelDataTypeFactoryImpl.JavaType) { return Primitive.ofBox( ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass()); } return null; }
/** * Returns the Primitive object for a given primitive or boxing class. * * <p>For example, <code>ofBoxOr(Long.class)</code> and * <code>ofBoxOr(long.class)</code> both return {@link #LONG}. */ public static Primitive ofBoxOr(Type type) { Primitive primitive = of(type); if (primitive == null) { primitive = ofBox(type); } return primitive; }
/** * Creates a ConstantExpression that has the Value property set * to the specified value. * * <p>Does the right thing for null, String, primitive values (e.g. int 12, * short 12, double 3.14 and boolean false), boxed primitives * (e.g. Integer.valueOf(12)), enums, classes, BigDecimal, BigInteger, * classes that have a constructor with a parameter for each field, and * arrays.</p> */ public static ConstantExpression constant(Object value) { Class type; if (value == null) { return ConstantUntypedNull.INSTANCE; } else { final Class clazz = value.getClass(); final Primitive primitive = Primitive.ofBox(clazz); if (primitive != null) { type = primitive.primitiveClass; } else { type = clazz; } } return new ConstantExpression(type, value); }
/** Converts e.g. "anInteger" to "anInteger.intValue()". */ public static Expression unbox(Expression expression) { Primitive primitive = Primitive.ofBox(expression.getType()); if (primitive == null) { return expression; } return unbox(expression, primitive); }
private static Object convert(Object o, Class clazz) { if (o == null) { return null; } Primitive primitive = Primitive.of(clazz); if (primitive != null) { clazz = primitive.boxClass; } else { primitive = Primitive.ofBox(clazz); } if (clazz.isInstance(o)) { return o; } if (o instanceof Date && primitive != null) { o = ((Date) o).getTime() / DateTimeUtils.MILLIS_PER_DAY; } if (o instanceof Number && primitive != null) { return primitive.number((Number) o); } return o; } }
private static boolean isNumeric(Class type) { switch (Primitive.flavor(type)) { case BOX: return Primitive.ofBox(type).isNumeric(); case PRIMITIVE: return Primitive.of(type).isNumeric(); default: return Number.class.isAssignableFrom(type); // e.g. BigDecimal } }
private static boolean isNumeric(Class type) { switch (Primitive.flavor(type)) { case BOX: return Primitive.ofBox(type).isNumeric(); case PRIMITIVE: return Primitive.of(type).isNumeric(); default: return Number.class.isAssignableFrom(type); // e.g. BigDecimal } }
return RexToLixTranslator.convert( x, Primitive.ofBox(x.getType()).primitiveClass);
return RexToLixTranslator.convert( x, Primitive.ofBox(x.getType()).primitiveClass);
ArrayTable.Representation chooseRep(int ordinal) { Primitive primitive = Primitive.of(clazz); Primitive boxPrimitive = Primitive.ofBox(clazz); Primitive p = primitive != null ? primitive : boxPrimitive; if (!containsNull && p != null) {
/** Converts from internal representation to JDBC representation used by * arguments of user-defined functions. For example, converts date values from * {@code int} to {@link java.sql.Date}. */ static Expression fromInternal(Expression e, Class<?> targetType) { if (e == ConstantUntypedNull.INSTANCE) { return e; } if (!(e.getType() instanceof Class)) { return e; } if (targetType.isAssignableFrom((Class) e.getType())) { return e; } if (targetType == java.sql.Date.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, e); } if (targetType == java.sql.Time.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_TIME.method, e); } if (targetType == java.sql.Timestamp.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_TIMESTAMP.method, e); } if (Primitive.is(e.type) && Primitive.isBox(targetType)) { // E.g. e is "int", target is "Long", generate "(long) e". return Expressions.convert_(e, Primitive.ofBox(targetType).primitiveClass); } return e; }
/** Converts from internal representation to JDBC representation used by * arguments of user-defined functions. For example, converts date values from * {@code int} to {@link java.sql.Date}. */ static Expression fromInternal(Expression e, Class<?> targetType) { if (e == ConstantUntypedNull.INSTANCE) { return e; } if (!(e.getType() instanceof Class)) { return e; } if (targetType.isAssignableFrom((Class) e.getType())) { return e; } if (targetType == java.sql.Date.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, e); } if (targetType == java.sql.Time.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_TIME.method, e); } if (targetType == java.sql.Timestamp.class) { return Expressions.call(BuiltInMethod.INTERNAL_TO_TIMESTAMP.method, e); } if (Primitive.is(e.type) && Primitive.isBox(targetType)) { // E.g. e is "int", target is "Long", generate "(long) e". return Expressions.convert_(e, Primitive.ofBox(targetType).primitiveClass); } return e; }
ArrayTable.Representation chooseRep(int ordinal) { Primitive primitive = Primitive.of(clazz); Primitive boxPrimitive = Primitive.ofBox(clazz); Primitive p = primitive != null ? primitive : boxPrimitive; if (!containsNull && p != null) {
return Expressions.unbox(expression, Primitive.ofBox(returnType));