public static Type box(Type type) { Primitive primitive = Primitive.of(type); if (primitive != null) { return primitive.boxClass; } else { return type; } }
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 static Type box(Type type) { Primitive primitive = Primitive.of(type); if (primitive != null) { return primitive.boxClass; } return type; }
/** * 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; }
/** * Converts a primitive class to a boxed class; returns other classes * unchanged. */ public static Class box(Class type) { Primitive primitive = of(type); return primitive == null ? type : primitive.boxClass; }
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 } }
/** * Converts a primitive type to a boxed type; returns other types * unchanged. */ public static Type box(Type type) { Primitive primitive = of(type); return primitive == null ? type : primitive.boxClass; }
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 } }
public ConstantExpression(Type type, Object value) { super(ExpressionType.Constant, type); this.value = value; if (value != null) { if (type instanceof Class) { Class clazz = (Class) type; Primitive primitive = Primitive.of(clazz); if (primitive != null) { clazz = primitive.boxClass; } if (!clazz.isInstance(value) && !((clazz == Float.class || clazz == Double.class) && value instanceof BigDecimal)) { throw new AssertionError( "value " + value + " does not match type " + type); } } } }
/** * Returns whether a parameter is assignable from an argument by virtue * of (a) sub-classing (e.g. Writer is assignable from PrintWriter) and (b) * up-casting (e.g. int is assignable from short). * * @param parameter Parameter type * @param argument Argument type * * @return Whether parameter can be assigned from argument */ private static boolean assignableFrom(Class parameter, Class argument) { return parameter.isAssignableFrom(argument) || parameter.isPrimitive() && argument.isPrimitive() && Primitive.of(parameter).assignableFrom(Primitive.of(argument)); }
BinaryExpression(ExpressionType nodeType, Type type, Expression expression0, Expression expression1) { super(nodeType, type); assert expression0 != null : "expression0 should not be null"; assert expression1 != null : "expression1 should not be null"; this.expression0 = expression0; this.expression1 = expression1; this.primitive = Primitive.of(expression0.getType()); }
private Expression maybeBox(Expression expression) { final Primitive primitive = Primitive.of(expression.getType()); if (primitive != null) { expression = Expressions.box(expression, primitive); } return expression; } }
/** Converts e.g. "anInteger" to "Integer.valueOf(anInteger)". */ public static Expression box(Expression expression) { Primitive primitive = Primitive.of(expression.getType()); if (primitive == null) { return expression; } return box(expression, primitive); }
private Expression maybeBox(Expression expression) { final Primitive primitive = Primitive.of(expression.getType()); if (primitive != null) { expression = Expressions.box(expression, primitive); } return expression; } }
static Expression getDefaultValue(Type type) { if (Primitive.is(type)) { Primitive p = Primitive.of(type); return Expressions.constant(p.defaultValue, type); } return Expressions.constant(null, type); }
static Expression getDefaultValue(Type type) { if (Primitive.is(type)) { Primitive p = Primitive.of(type); return Expressions.constant(p.defaultValue, type); } return Expressions.constant(null, type); }
public Expression generateSelector(final ParameterExpression parameter, final List<Integer> fields, List<Integer> usedFields, JavaRowFormat targetFormat) { final PhysType targetPhysType = project(fields, true, targetFormat); final List<Expression> expressions = new ArrayList<>(); for (Ord<Integer> ord : Ord.zip(fields)) { final Integer field = ord.e; if (usedFields.contains(field)) { expressions.add(fieldReference(parameter, field)); } else { final Primitive primitive = Primitive.of(targetPhysType.fieldClass(ord.i)); expressions.add( Expressions.constant( primitive != null ? primitive.defaultValue : null)); } } for (Integer field : fields) { expressions.add(Expressions.constant(!usedFields.contains(field))); } return Expressions.lambda(Function1.class, targetPhysType.record(expressions), parameter); }
@Override protected void implementNotNullReset(AggContext info, AggResetContext reset) { Expression acc = reset.accumulator().get(0); Primitive p = Primitive.of(acc.getType()); boolean isMin = MIN == info.aggregation(); Object inf = p == null ? null : (isMin ? p.max : p.min); reset.currentBlock().add( Expressions.statement( Expressions.assign(acc, Expressions.constant(inf, acc.getType())))); }
@Override protected void implementNotNullReset(AggContext info, AggResetContext reset) { Expression acc = reset.accumulator().get(0); Primitive p = Primitive.of(acc.getType()); boolean isMin = MIN == info.aggregation(); Object inf = p == null ? null : (isMin ? p.max : p.min); reset.currentBlock().add( Expressions.statement( Expressions.assign(acc, Expressions.constant(inf, acc.getType())))); }