All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vertexium.cypher.ast.model.CypherMatchClause Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.ast.model;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CypherMatchClause extends CypherClause {
    private final CypherListLiteral patternParts;
    private final CypherAstBase whereExpression;
    private final boolean optional;

    public CypherMatchClause(
        boolean optional,
        CypherListLiteral patternParts,
        CypherAstBase whereExpression
    ) {
        this.optional = optional;
        this.patternParts = patternParts;
        this.whereExpression = whereExpression;
    }

    public boolean isOptional() {
        return optional;
    }

    public CypherListLiteral getPatternParts() {
        return patternParts;
    }

    public CypherAstBase getWhereExpression() {
        return whereExpression;
    }

    @Override
    public String toString() {
        return String.format(
            "%sMATCH %s%s",
            isOptional() ? "OPTIONAL " : "",
            getPatternParts().stream().map(CypherPatternPart::toString).collect(Collectors.joining(", ")),
            getWhereExpression() == null ? "" : " WHERE " + getWhereExpression()
        );
    }

    @Override
    public Stream getChildren() {
        if (whereExpression != null) {
            return Stream.concat(
                patternParts.stream(),
                Stream.of(whereExpression)
            );
        } else {
            return patternParts.stream();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy