use of com.rethinkdb.model.ReqlLambda in project MantaroBot by Mantaro.
the class Util method toReqlAst.
@SuppressWarnings("unchecked")
private static ReqlAst toReqlAst(Object val, int remainingDepth) {
if (remainingDepth <= 0) {
throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst");
}
if (val instanceof ReqlAst) {
return (ReqlAst) val;
}
if (val instanceof Object[]) {
Arguments innerValues = new Arguments();
for (Object innerValue : Arrays.asList((Object[]) val)) {
innerValues.add(toReqlAst(innerValue, remainingDepth - 1));
}
return new MakeArray(innerValues, null);
}
if (val instanceof List) {
Arguments innerValues = new Arguments();
for (Object innerValue : (List) val) {
innerValues.add(toReqlAst(innerValue, remainingDepth - 1));
}
return new MakeArray(innerValues, null);
}
if (val instanceof Map) {
Map<String, ReqlAst> obj = new MapObject<>();
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) val).entrySet()) {
if (!(entry.getKey() instanceof String)) {
throw new ReqlDriverCompileError("Object keys can only be strings");
}
obj.put((String) entry.getKey(), toReqlAst(entry.getValue()));
}
return MakeObj.fromMap(obj);
}
if (val instanceof ReqlLambda) {
return Func.fromLambda((ReqlLambda) val);
}
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
if (val instanceof LocalDateTime) {
ZoneId zid = ZoneId.systemDefault();
DateTimeFormatter fmt2 = fmt.withZone(zid);
return Iso8601.fromString(((LocalDateTime) val).format(fmt2));
}
if (val instanceof ZonedDateTime) {
return Iso8601.fromString(((ZonedDateTime) val).format(fmt));
}
if (val instanceof OffsetDateTime) {
return Iso8601.fromString(((OffsetDateTime) val).format(fmt));
}
if (val instanceof Number || val instanceof Boolean || val instanceof String) {
return new Datum(val);
}
if (val == null) {
return new Datum(null);
}
// val is a non-null POJO, let's introspect its public properties
return toReqlAst(toMap(val));
}
Aggregations