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

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

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

import java.util.Map;
import java.util.stream.Stream;

import static org.vertexium.util.StreamUtils.stream;

public abstract class CypherElementPattern extends CypherAstBase {
    private String name;
    private final CypherMapLiteral propertiesMap;

    public CypherElementPattern(String name, CypherMapLiteral propertiesMap) {
        if (propertiesMap == null) {
            propertiesMap = new CypherMapLiteral<>();
        }
        this.name = name;
        this.propertiesMap = propertiesMap;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public CypherMapLiteral getPropertiesMap() {
        return propertiesMap;
    }

    public boolean hasProperties() {
        return propertiesMap != null && propertiesMap.size() > 0;
    }

    @Override
    public Stream getChildren() {
        return stream(propertiesMap.entrySet()).map(Map.Entry::getValue);
    }

    @Override
    public String toString() {
        return this.getClass().getName() + "{" +
            "name='" + name + '\'' +
            '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        CypherElementPattern that = (CypherElementPattern) o;

        if (name != null ? !name.equals(that.name) : that.name != null) {
            return false;
        }
        return propertiesMap.equals(that.propertiesMap);
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + propertiesMap.hashCode();
        return result;
    }

    public int getConstraintCount() {
        return propertiesMap.size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy