io.github.kiryu1223.expressionTree.expressions.ForExpression Maven / Gradle / Ivy
package io.github.kiryu1223.expressionTree.expressions;
import java.util.List;
public class ForExpression extends Expression
{
private final List init;
private final Expression condition;
private final List step;
private final Expression body;
public ForExpression(List init, Expression condition, List step, Expression body)
{
this.init = init;
this.condition = condition;
this.step = step;
this.body = body;
}
public List getInit()
{
return init;
}
public Expression getCondition()
{
return condition;
}
public List getStep()
{
return step;
}
public Expression getBody()
{
return body;
}
@Override
public Kind getKind()
{
return Kind.For;
}
@Override
public String toString()
{
// todo:多条件for循环未写
StringBuilder sb = new StringBuilder();
sb.append("for (");
for (Expression expression : init)
{
sb.append(expression);
}
sb.append(";");
if (condition != null)
{
sb.append(condition);
}
sb.append(";");
for (Expression expression : step)
{
sb.append(expression);
}
sb.append(") ").append(body);
return sb.toString();
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ForExpression that = (ForExpression) obj;
return init.equals(that.init) && condition.equals(that.condition)
&& step.equals(that.step) && body.equals(that.body);
}
}