/** * 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); }
private static Constructor matchingConstructor(Object value) { final Field[] fields = value.getClass().getFields(); for (Constructor<?> constructor : value.getClass().getConstructors()) { if (argsMatchFields(fields, constructor.getParameterTypes())) { return constructor; } } return null; }
private static ExpressionWriter writeMap(ExpressionWriter writer, Map map) { writer.append("com.google.common.collect.ImmutableMap."); if (map.isEmpty()) { return writer.append("of()"); } if (map.size() < 5) { return map(writer, map, "of(", ",\n", ")"); } return map(writer, map, "builder().put(", ")\n.put(", ").build()"); }
escapeString(writer.getBuf(), (String) value); return writer; if (primitive2 != null) { writer.append(primitive2.boxClass.getSimpleName() + ".valueOf("); write(writer, value, primitive2.primitiveClass); return writer.append(")"); list(writer, Primitive.asList(value), "[] {\n", ",\n", "}"); return writer; return writer; list(writer, (List) value, "java.util.Arrays.asList(", ",\n", ")"); return writer; return writeMap(writer, (Map) value); Constructor constructor = matchingConstructor(value); if (constructor != null) { writer.append("new ").append(value.getClass()); list(writer, Arrays.stream(value.getClass().getFields()) .map(field -> {
return rexBuilder.makeLiteral((Boolean) value); } else { return rexBuilder.makeLiteral(constant.toString());
return rexBuilder.makeLiteral((Boolean) value); } else { return rexBuilder.makeLiteral(constant.toString());
return rexBuilder.makeLiteral((Boolean) value); } else { return rexBuilder.makeLiteral(constant.toString());
return new ConstantExpression(type, value);