public class CalculatorHandler extends Object implements JExpressionHandler
Double.Boolean.addVariable(String, Object). addFunction(JExpressionFunction).| Constructor and Description |
|---|
CalculatorHandler()
Construtor.
|
CalculatorHandler(double tolerance)
Construtor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFunction(JExpressionFunction function)
Adiciona uma função.
|
void |
addVariable(String name,
Object value)
Adiciona uma variável e seu respectivo valor.
|
List<String> |
getFunctionNames()
Retorna a lista com o nome das funções definidas.
|
List<String> |
getVarNames()
Retorna a lista com o nome das variáveis definidas.
|
Object |
handleAnd(Object first,
Object second)
Callback da operação '&&'.
|
Object |
handleDivision(Object first,
Object second)
Callback de operação '/'.
|
Object |
handleDouble(Double value)
Callback para valores
Double. |
Object |
handleEqual(Object first,
Object second)
Callback da operação '=='.
|
Object |
handleField(Object object,
String field)
Callback de acesso a um campo de objeto.
|
Object |
handleFunctionCall(String functionName,
List<Object> params)
Callback de chamada de função.
|
Object |
handleGreater(Object first,
Object second)
Callback da operação '>'.
|
Object |
handleGreaterEqual(Object first,
Object second)
Callback da operação '>='.
|
Object |
handleIndex(Object object,
Object index)
Callback de indexação.
|
Object |
handleLower(Object first,
Object second)
Callback da operação '<'.
|
Object |
handleLowerEqual(Object first,
Object second)
Callback da operação '<='.
|
Object |
handleMinus(Object first,
Object second)
Callback de operação '-'.
|
Object |
handleNot(Object object)
Callback do operador unário '!'.
|
Object |
handleNotEqual(Object first,
Object second)
Callback da operação '!='.
|
Object |
handleOr(Object first,
Object second)
Callback de operação '||'.
|
Object |
handlePlus(Object first,
Object second)
Callback da operação '+'.
|
Object |
handlePow(Object first,
Object second)
Callback da operação '^'.
|
Object |
handleQuestion(Object condition,
Object then,
Object otherwise)
Callback do operador ternário if-then-else (a ? b : c)
|
Object |
handleTimes(Object first,
Object second)
Callback de operação '*'.
|
Object |
handleUnaryMinus(Object object)
Callback do operador unário '-'.
|
Object |
handleVar(String name)
Callback de variável.
|
boolean |
hasFunction(String name)
Retorna true se existir uma função com o dado nome, false caso contrário.
|
boolean |
hasVariable(String name)
Retorna true se existir uma variável com o dado nome, false caso contrário.
|
void |
registerBasicFunctions()
Registra funções básicas.
|
void |
removeAllFunctions()
Remove todas as funções.
|
void |
removeAllVariables()
Remove todas as variáveis.
|
void |
removeFunction(String name)
Remove função.
|
void |
removeVariable(String name)
Remove variável.
|
public CalculatorHandler()
public CalculatorHandler(double tolerance)
tolerance - tolerância nas operações de double.public void registerBasicFunctions()
public void addVariable(String name, Object value)
name - nome da variável.value - valor.public boolean hasVariable(String name)
name - nome da variável.public void removeVariable(String name)
name - nome da variável.public void removeAllVariables()
public void addFunction(JExpressionFunction function)
function - função.public boolean hasFunction(String name)
name - nome da função.public void removeFunction(String name)
name - nome da função.public void removeAllFunctions()
public List<String> getVarNames()
public List<String> getFunctionNames()
public Object handleDouble(Double value) throws Exception
Double.handleDouble in interface JExpressionHandlervalue - valor.Exception - em caso de erro.public Object handlePlus(Object first, Object second) throws Exception
handlePlus in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleMinus(Object first, Object second) throws Exception
handleMinus in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleTimes(Object first, Object second) throws Exception
handleTimes in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleDivision(Object first, Object second) throws Exception
handleDivision in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handlePow(Object first, Object second) throws Exception
handlePow in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleOr(Object first, Object second) throws Exception
handleOr in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleAnd(Object first, Object second) throws Exception
handleAnd in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleEqual(Object first, Object second) throws Exception
handleEqual in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleNotEqual(Object first, Object second) throws Exception
handleNotEqual in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleGreater(Object first, Object second) throws Exception
handleGreater in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleGreaterEqual(Object first, Object second) throws Exception
handleGreaterEqual in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleLower(Object first, Object second) throws Exception
handleLower in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleLowerEqual(Object first, Object second) throws Exception
handleLowerEqual in interface JExpressionHandlerfirst - primeiro operando.second - segundo operando.Exception - em caso de erro.public Object handleQuestion(Object condition, Object then, Object otherwise) throws Exception
handleQuestion in interface JExpressionHandlercondition - condição.then - ação.otherwise - caso contrário.Exception - em caso de erro.public Object handleUnaryMinus(Object object) throws Exception
handleUnaryMinus in interface JExpressionHandlerobject - operando.Exception - em caso de erro.public Object handleNot(Object object) throws Exception
handleNot in interface JExpressionHandlerobject - operando.Exception - em caso de erro.public Object handleVar(String name) throws Exception
handleVar in interface JExpressionHandlername - nome da variável.Exception - em caso de erro.public Object handleFunctionCall(String functionName, List<Object> params) throws Exception
handleFunctionCall in interface JExpressionHandlerfunctionName - nome função.params - lista de parâmetros.Exception - em caso de erro.public Object handleIndex(Object object, Object index) throws Exception
handleIndex in interface JExpressionHandlerobject - objeto a ser indexado.index - índice.Exception - em caso de erro.public Object handleField(Object object, String field) throws Exception
handleField in interface JExpressionHandlerobject - primeiro operando.field - campo.Exception - em caso de erro.Copyright © 2007–2014 Tecgraf/PUC-Rio. All rights reserved.