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

com.tinkerpop.gremlin.structure.strategy.StrategyWrappedVariables Maven / Gradle / Ivy

package com.tinkerpop.gremlin.structure.strategy;

import com.tinkerpop.gremlin.structure.Graph;

import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public class StrategyWrappedVariables implements StrategyWrapped, Graph.Variables {

    protected final StrategyWrappedGraph strategyWrappedGraph;
    private final Graph.Variables baseVariables;
    private final Strategy.Context variableStrategyContext;

    public StrategyWrappedVariables(final Graph.Variables variables, final StrategyWrappedGraph strategyWrappedGraph) {
        if (variables instanceof StrategyWrapped) throw new IllegalArgumentException(
                String.format("The variables %s is already StrategyWrapped and must be a base Variables", variables));
        this.baseVariables = variables;
        this.strategyWrappedGraph = strategyWrappedGraph;
        this.variableStrategyContext = new Strategy.Context<>(strategyWrappedGraph.getBaseGraph(), this);
    }

    @Override
    public Set keys() {
        return this.strategyWrappedGraph.strategy().compose(
                s -> s.getVariableKeysStrategy(variableStrategyContext),
                this.baseVariables::keys).get();
    }

    @Override
    public  Optional get(final String key) {
        return this.strategyWrappedGraph.strategy().compose(
                s -> s.getVariableGetStrategy(variableStrategyContext),
                this.baseVariables::get).apply(key);
    }

    @Override
    public void set(final String key, final Object value) {
        this.strategyWrappedGraph.strategy().compose(
                s -> s.getVariableSetStrategy(variableStrategyContext),
                this.baseVariables::set).accept(key, value);
    }

    @Override
    public void remove(final String key) {
        this.strategyWrappedGraph.strategy().compose(
                s -> s.getVariableRemoveStrategy(variableStrategyContext),
                this.baseVariables::remove).accept(key);
    }

    @Override
    public Map asMap() {
        return this.strategyWrappedGraph.strategy().compose(
                s -> s.getVariableAsMapStrategy(variableStrategyContext),
                this.baseVariables::asMap).get();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy