Skip to content
Snippets Groups Projects

Draft: Add sequence generators

Open Bernhard Johannes Berger requested to merge 160-new-generator-type-sequencer into develop
2 unresolved threads
Files
5
import java.util.Iterator;
import org.eclipse.emf.ecore.EStructuralFeature;
import de.evoal.pipeline.api.model.ComponentImpl;
import de.evoal.pipeline.api.model.TypedEObject;
import lombok.NonNull;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
public class Sequence extends ComponentImpl implements Visitable{
private double start_value;
private String sequence;
private String params;
private double step_size;
private double current_value;
private Expression exp;
public Sequence(double start_value, String sequence, String params, double step_size) {
this.start_value = start_value;
this.sequence = sequence;
this.params = params;
this.step_size = step_size;
this.current_value = this.start_value;
exp = new ExpressionBuilder(sequence).variable(params).build();
}
public double getCurrent_value() {
return current_value;
}
public void setCurrent_value(double current_value) {
this.current_value = current_value;
}
public double getStart_value() {
return start_value;
}
public void setStart_value(double start_value) {
this.start_value = start_value;
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public double getStep_size() {
return step_size;
}
public void setStep_size(double step_size) {
this.step_size = step_size;
}
private double getValueOf(double StartValue)
{
return exp.setVariable(this.params,StartValue).evaluate();
}
public double getNextValueOfSequence()
{
double result = exp.setVariable(this.params,this.current_value).evaluate();
System.out.println("Next calculated Value of "+ this.sequence + " we started at "+ this.start_value +" the new value we plugged in is "+ this.current_value +" the result is " + result);
this.current_value=this.current_value + this.step_size;
return result;
}
public double getNextValue()
{
double old=this.current_value;
this.current_value=this.current_value + this.step_size;
double result = exp.setVariable(this.params,this.current_value).evaluate();
System.out.println("Next calculated Value of "+ this.sequence + " we started at "+ old +" the new value we plugged in is "+ this.current_value +" the result is " + result);
return result;
}
@Override
public void accept(Visitor visitor)
{
visitor.visit(this);
}
//I am a bit confused as to how this works or even how this plays into the whole set up.
@Override
public @NonNull TypedEObject apply(@NonNull TypedEObject object) {
//Currently I want to do the BEAR MINIMUM just get a number back
final Iterator<EStructuralFeature> iterator = getWrites().iterator(); //iterator that lets us walk over variable that we need to write
while(iterator.hasNext())
{
final EStructuralFeature feature = iterator.next();
double value= this.getNextValueOfSequence();
object.eSet(feature, value);
}
return object;
}
}
\ No newline at end of file
Loading