Class If<T>
- java.lang.Object
-
- org.protelis.lang.interpreter.impl.AbstractProtelisAST<T>
-
- org.protelis.lang.interpreter.impl.If<T>
-
- Type Parameters:
T
- the return type of this If
- All Implemented Interfaces:
java.io.Serializable
,ProtelisAST<T>
,WithBytecode
public final class If<T> extends AbstractProtelisAST<T>
Branch, restricting domain of true and false branches into their own aligned subspaces.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description If(Metadata metadata, ProtelisAST<java.lang.Boolean> cond, ProtelisAST<T> then, ProtelisAST<T> otherwise)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
evaluate(ExecutionContext context)
Evaluates this AST node.Bytecode
getBytecode()
ProtelisAST<java.lang.Boolean>
getConditionExpression()
ProtelisAST<T>
getElseExpression()
ProtelisAST<T>
getThenExpression()
protected boolean
isNullable()
java.lang.String
toString()
-
Methods inherited from class org.protelis.lang.interpreter.impl.AbstractProtelisAST
branchesToString, branchesToString, eval, forEach, forEachWithIndex, getBranch, getBranches, getBranchesNumber, getMetadata, getName, stringFor
-
-
-
-
Constructor Detail
-
If
public If(@Nonnull Metadata metadata, @Nonnull ProtelisAST<java.lang.Boolean> cond, @Nonnull ProtelisAST<T> then, @Nonnull ProtelisAST<T> otherwise)
- Parameters:
metadata
- AMetadata
object containing information about the code that generated this AST node.cond
- conditionthen
- branch to execute if condition is true (erase otherwise)otherwise
- branch to execute if condition is false (erase otherwise)
-
-
Method Detail
-
evaluate
public T evaluate(ExecutionContext context)
Description copied from class:AbstractProtelisAST
Evaluates this AST node. This method can throw any exception,AbstractProtelisAST
takes care of storing the necessary metadata.- Specified by:
evaluate
in classAbstractProtelisAST<T>
- Parameters:
context
- the execution context- Returns:
- the result of the evaluation
-
getConditionExpression
public ProtelisAST<java.lang.Boolean> getConditionExpression()
- Returns:
- the
ProtelisAST
of the condition expression
-
getElseExpression
public ProtelisAST<T> getElseExpression()
- Returns:
- the
ProtelisAST
of the else expression
-
getThenExpression
public ProtelisAST<T> getThenExpression()
- Returns:
- the
ProtelisAST
of the then expression
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractProtelisAST<T>
-
isNullable
protected boolean isNullable()
- Overrides:
isNullable
in classAbstractProtelisAST<T>
- Returns:
- true if this node can get annotated with null values - namely, if it is an interaction with Java
-
-