📄 casetoken.java
字号:
package jmathlib.core.tokens;
import jmathlib.core.interpreter.ErrorLogger;
/**Used to implement if-then-else operations within an expression*/
public class CaseToken extends CommandToken
{
/**condition */
OperandToken value;
/** { code } to execute if condition is true*/
OperandToken code;
/**Constructor setting ifRelation and ifCode
@param _ifRelation = the test relation
@param _ifCode = the code to execute if the test is true*/
public CaseToken(OperandToken _value, OperandToken _code)
{
value = _value;
code = _code;
}
public OperandToken getExpression()
{
return code;
}
/**evaluates the operator
@param operands = the operators operands
@return the result of the test as an OperandToken*/
public OperandToken evaluate(Token[] operands)
{
if(value != null)
{
Expression exp = new Expression(new RelationOperatorToken('e'),
((OperandToken)operands[0]),
value);
OperandToken result = exp.evaluate(null);
if(result instanceof LogicalToken)
{
if(((LogicalToken)result).getValue(0))
{
ErrorLogger.debugLine("case is TRUE ");
code.evaluate(null);
return new LogicalToken(true);
}
}
}
else
{
ErrorLogger.debugLine("case is DEFAULT ");
code.evaluate(null);
return new LogicalToken(true);
}
return null;
}
/**Convert the operator to a string
@return the operator as a string*/
public String toString()
{
if (value != null)
return "case: " + value.toString();
else
return "default: ";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -