tech.ydb.yoj.databind.expression.AndExpr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoj-databind Show documentation
Show all versions of yoj-databind Show documentation
Core data-binding logic used by YOJ (YDB ORM for Java) to convert
between Java objects and database rows (or anything representable by
a Java Map, really).
The newest version!
package tech.ydb.yoj.databind.expression;
import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.Value;
import tech.ydb.yoj.databind.schema.Schema;
import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
@Value
@AllArgsConstructor
public class AndExpr implements FilterExpression {
@NonNull
Schema schema;
@NonNull
List> children;
@Override
public Type getType() {
return Type.AND;
}
@Override
public V visit(@NonNull Visitor visitor) {
return visitor.visitAndExpr(this);
}
@Override
public FilterExpression and(@NonNull FilterExpression other) {
if (other instanceof AndExpr>) {
return new AndExpr<>(schema, ImmutableList.>builder()
.addAll(children)
.addAll(((AndExpr) other).children)
.build());
} else {
return new AndExpr<>(schema, ImmutableList.>builder()
.addAll(children)
.add(other)
.build());
}
}
@Override
public Stream> stream() {
return children.stream();
}
@Override
public AndExpr forSchema(@NonNull Schema dstSchema, @NonNull UnaryOperator pathTransformer) {
return new AndExpr<>(dstSchema, this.children.stream()
.map(expr -> expr.forSchema(dstSchema, pathTransformer))
.collect(toList()));
}
@Override
public String toString() {
return stream().map(Object::toString).collect(joining(") AND (", "(", ")"));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy