io.github.vmzakharov.ecdataframe.dsl.SimpleEvalContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dataframe-ec Show documentation
Show all versions of dataframe-ec Show documentation
A tabular data structure based on the Eclipse Collections framework
The newest version!
package io.github.vmzakharov.ecdataframe.dsl;
import io.github.vmzakharov.ecdataframe.dataset.HierarchicalDataSet;
import io.github.vmzakharov.ecdataframe.dsl.value.Value;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.factory.Maps;
import static io.github.vmzakharov.ecdataframe.util.ExceptionFactory.exceptionByKey;
public class SimpleEvalContext
extends EvalContextAbstract
{
private final MutableMap dataSets = Maps.mutable.of();
@Override
public Value getVariable(String newVariableName)
{
Value value = this.getContextVariables().get(newVariableName);
if (value == null)
{
exceptionByKey("DSL_VAR_UNINITIALIZED").with("variableName", newVariableName).fire();
}
return value;
}
@Override
public Value getVariableOrDefault(String newVariableName, Value defaultValue)
{
Value value = this.getContextVariables().get(newVariableName);
return (value == null) ? defaultValue : value;
}
@Override
public void addDataSet(HierarchicalDataSet dataSet)
{
this.dataSets.put(dataSet.getName(), dataSet);
}
@Override
public HierarchicalDataSet getDataSet(String dataSetName)
{
return this.dataSets.get(dataSetName);
}
@Override
public RichIterable getVariableNames()
{
return this.getContextVariables().keysView();
}
}