
org.diirt.datasource.formula.LastOfChannelExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datasource-formula Show documentation
Show all versions of datasource-formula Show documentation
An extensible formula language suitable for real-time calculation.
The newest version!
/**
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
*/
package org.diirt.datasource.formula;
import java.util.List;
import org.diirt.datasource.ReadRecipeBuilder;
import org.diirt.datasource.ReadFunction;
import org.diirt.datasource.expression.DesiredRateExpression;
import org.diirt.datasource.expression.DesiredRateExpressionImpl;
import org.diirt.datasource.expression.DesiredRateExpressionList;
import static org.diirt.datasource.ExpressionLanguage.*;
import org.diirt.datasource.PVDirector;
/**
*
* @author carcassi
*/
class LastOfChannelExpression implements DesiredRateExpression {
private final DesiredRateExpression expression;
private final Class clazz;
public LastOfChannelExpression(String name, Class clazz) {
this.expression = latestValueOf(channel(name, clazz, Object.class));
this.clazz = clazz;
}
@Override
public DesiredRateExpression as(String name) {
return expression.as(name);
}
@Override
public String getName() {
return expression.getName();
}
@Override
public void fillReadRecipe(PVDirector director, ReadRecipeBuilder builder) {
expression.fillReadRecipe(director, builder);
}
@Override
public ReadFunction getFunction() {
return expression.getFunction();
}
@Override
public DesiredRateExpressionImpl getDesiredRateExpressionImpl() {
return expression.getDesiredRateExpressionImpl();
}
@Override
public DesiredRateExpressionList and(DesiredRateExpressionList extends T> expressions) {
return expression.and(expressions);
}
@Override
public List> getDesiredRateExpressions() {
return expression.getDesiredRateExpressions();
}
public LastOfChannelExpression cast(Class clazz) {
if (clazz.isAssignableFrom(this.clazz)) {
@SuppressWarnings("unchecked")
LastOfChannelExpression result = (LastOfChannelExpression) this;
return result;
}
if (this.clazz.isAssignableFrom(clazz)) {
return new LastOfChannelExpression(getName(), clazz);
}
throw new IllegalArgumentException("Cannot cast expression of type " + this.clazz + " to type " + clazz);
}
public Class getType() {
return clazz;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy