![JAR search and dependency download from the Maven repository](/logo.png)
io.github.vmzakharov.ecdataframe.dsl.EvalContextAbstract 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
package io.github.vmzakharov.ecdataframe.dsl;
import io.github.vmzakharov.ecdataframe.dsl.value.DateValue;
import io.github.vmzakharov.ecdataframe.dsl.value.LongValue;
import io.github.vmzakharov.ecdataframe.dsl.value.Value;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.factory.Maps;
import java.time.LocalDate;
import static io.github.vmzakharov.ecdataframe.util.ExceptionFactory.exceptionByKey;
abstract public class EvalContextAbstract
implements EvalContext
{
private MutableMap declaredFunctions = Maps.mutable.of();
private final MutableMap contextVariables = Maps.mutable.of();
@Override
public boolean hasVariable(String variableName)
{
return this.contextVariables.containsKey(variableName);
}
@Override
public void removeVariable(String variableName)
{
this.contextVariables.remove(variableName);
}
@Override
public void removeAllVariables()
{
this.contextVariables.clear();
}
protected MutableMap getContextVariables()
{
return this.contextVariables;
}
@Override
public Value setVariable(String variableName, Value newValue)
{
if (this.hasVariable(variableName))
{
exceptionByKey("DSL_VAR_IMMUTABLE").with("variableName", variableName).fire();
}
this.getContextVariables().put(variableName, newValue);
return newValue;
}
@Override
public MapIterable getDeclaredFunctions()
{
return this.declaredFunctions;
}
@Override
public void setDeclaredFunctions(MutableMap newDeclaredFunctions)
{
this.declaredFunctions = newDeclaredFunctions;
}
@Override
public FunctionScript getDeclaredFunction(String functionName)
{
return this.declaredFunctions.get(functionName);
}
// helps avoid recursion
public void loadFunctionsExcept(MapIterable functionsFromOutside, String nameToExclude)
{
functionsFromOutside.forEachKeyValue((k, v) -> {
if (!k.equals(nameToExclude))
{
this.declaredFunctions.put(k, v);
}
});
}
@Override
public String getString(String variableName)
{
return this.getVariable(variableName).stringValue();
}
@Override
public long getLong(String variableName)
{
return ((LongValue) this.getVariable(variableName)).longValue();
}
@Override
public LocalDate getDate(String variableName)
{
return ((DateValue) this.getVariable(variableName)).dateValue();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy