io.github.vmzakharov.ecdataframe.dataframe.DfDoubleColumnComputed Maven / Gradle / Ivy
package io.github.vmzakharov.ecdataframe.dataframe;
import io.github.vmzakharov.ecdataframe.dsl.Expression;
import io.github.vmzakharov.ecdataframe.dsl.value.DoubleValue;
import io.github.vmzakharov.ecdataframe.dsl.value.Value;
import io.github.vmzakharov.ecdataframe.util.ExpressionParserHelper;
public class DfDoubleColumnComputed
extends DfDoubleColumn
implements DfColumnComputed
{
private final String expressionAsString;
private final Expression expression;
public DfDoubleColumnComputed(DataFrame newDataFrame, String newName, String newExpressionAsString)
{
super(newDataFrame, newName);
this.expressionAsString = newExpressionAsString;
this.expression = ExpressionParserHelper.DEFAULT.toExpressionOrScript(this.expressionAsString);
}
@Override
public Object getObject(int rowIndex)
{
Value result = this.getValue(rowIndex);
return result.isVoid() ? null : ((DoubleValue) result).doubleValue();
}
@Override
public double getDouble(int rowIndex)
{
Value result = this.getValue(rowIndex);
if (result.isVoid())
{
throw new NullPointerException("Null value at " + this.getName() + "[" + rowIndex + "]");
}
return ((DoubleValue) result).doubleValue();
}
@Override
protected void addAllItemsFrom(DfDoubleColumn doubleColumn)
{
this.throwUnmodifiableColumnException();
}
@Override
public int getSize()
{
return this.getDataFrame().rowCount();
}
@Override
public String getExpressionAsString()
{
return this.expressionAsString;
}
@Override
public Expression getExpression()
{
return this.expression;
}
@Override
public boolean isNull(int rowIndex)
{
return this.getObject(rowIndex) == null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy