
io.polyglotted.eswrapper.query.request.Expression Maven / Gradle / Ivy
package io.polyglotted.eswrapper.query.request;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.polyglotted.eswrapper.query.ExpressionType;
import lombok.RequiredArgsConstructor;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
@RequiredArgsConstructor
public final class Expression {
public static final Expression NilExpression = new Expression("_nil_", "_nil_", ImmutableMap.of(), ImmutableList.of());
public static final String ValueKey = "_val";
public final String operation;
public final String label;
public final ImmutableMap args;
public final ImmutableList children;
public static Expression withMap(String operation, String label, java.util.Map args) {
return new Expression(checkNotNull(operation), checkNotNull(label), ImmutableMap.copyOf(args), ImmutableList.of());
}
public static Expression withValue(ExpressionType expressionType, String label, Object valueArg) {
return new Expression(expressionType.name(), checkNotNull(label), ImmutableMap.of(ValueKey, valueArg), ImmutableList.of());
}
public static > Expression withArray(ExpressionType expressionType, String label, List valueArg) {
return new Expression(expressionType.name(), checkNotNull(label), ImmutableMap.of(ValueKey, valueArg), ImmutableList.of());
}
public static Expression withOnlyChildren(ExpressionType expressionType, String label, Iterable list) {
return new Expression(expressionType.name(), checkNotNull(label), ImmutableMap.of(), ImmutableList.copyOf(list));
}
public T valueArg() {
return argFor(ValueKey, null);
}
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy