tech.ydb.yoj.databind.expression.OrExpr 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;
import static tech.ydb.yoj.databind.expression.FilterExpression.Type.OR;
@Value
@AllArgsConstructor
public class OrExpr implements FilterExpression {
@NonNull
Schema schema;
@NonNull
List> children;
@Override
public Type getType() {
return OR;
}
@Override
public V visit(@NonNull Visitor visitor) {
return visitor.visitOrExpr(this);
}
@Override
public FilterExpression or(@NonNull FilterExpression other) {
if (other instanceof OrExpr>) {
return new OrExpr<>(schema, ImmutableList.>builder()
.addAll(children)
.addAll(((OrExpr) other).children)
.build());
} else {
return new OrExpr<>(schema, ImmutableList.>builder()
.addAll(children)
.add(other)
.build());
}
}
@Override
public Stream> stream() {
return children.stream();
}
@Override
public OrExpr forSchema(@NonNull Schema dstSchema, @NonNull UnaryOperator pathTransformer) {
return new OrExpr<>(dstSchema, this.children.stream()
.map(expr -> expr.forSchema(dstSchema, pathTransformer))
.collect(toList()));
}
@Override
public String toString() {
return stream().map(Object::toString).collect(joining(") OR (", "(", ")"));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy