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

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

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

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

public class CypherMapLiteral extends CypherLiteral> {
    public CypherMapLiteral(Map map) {
        super(map);
    }

    public CypherMapLiteral() {
        this(new HashMap<>());
    }

    public int size() {
        return getValue().size();
    }

    public Iterable> entrySet() {
        return getValue().entrySet();
    }

    public TValue get(TKey key) {
        return getValue().get(key);
    }

    public Map toMap() {
        return getValue();
    }

    public Set getKeys() {
        return getValue().keySet();
    }

    @Override
    public Stream getChildren() {
        return getValue().entrySet().stream()
            .flatMap(entry -> {
                if (entry.getKey() instanceof CypherAstBase && entry.getValue() instanceof CypherAstBase) {
                    return Stream.of((CypherAstBase) entry.getKey(), (CypherAstBase) entry.getValue());
                }
                if (entry.getValue() instanceof CypherAstBase) {
                    return Stream.of((CypherAstBase) entry.getValue());
                }
                if (entry.getKey() instanceof CypherAstBase) {
                    return Stream.of((CypherAstBase) entry.getKey());
                }
                return Stream.empty();
            });
    }

    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        result.append("{");
        boolean first = true;
        for (Map.Entry entry : getValue().entrySet()) {
            if (!first) {
                result.append(", ");
            }
            result.append(entry.getKey());
            result.append(": ");
            result.append(entry.getValue());
            first = false;
        }
        result.append("}");
        return result.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy