All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax0.jamal.prog.commands.If Maven / Gradle / Ivy

The newest version!
package javax0.jamal.prog.commands;

import javax0.jamal.api.BadSyntax;

public class If implements Command {
    private final Expression condition;
    private final Block then;
    private final Block otherwise;

    public If(final Expression condition, final Block then, final Block otherwise) {
        this.condition = condition;
        this.then = then;
        this.otherwise = otherwise;
    }


    @Override
    public String execute(final Context ctx) throws BadSyntax {
        ctx.step();
        if( Operation.isTrue(condition.execute(ctx))){
            return then.execute(ctx);
        } else {
            return otherwise.execute(ctx);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy