|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttecgraf.javautils.jexpression.util.CalculatorHandler
public class CalculatorHandler
Implementação de um tratador de expressões que adota as seguintes convenções:
1 - Operadores aritméticos operam sobre Double.
2 - Operadores relacionais operam sobre Boolean.
3 - Operações aritméticas operam usado uma tolerância que pode ser definida
no construtor.
4 - Variáveis podem ser definidas a partir do método
addVariable(String, Object).
| Constructor Summary | |
|---|---|
CalculatorHandler()
Construtor. |
|
CalculatorHandler(double tolerance)
Construtor. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CalculatorHandler()
public CalculatorHandler(double tolerance)
tolerance - tolerância nas operações de double.| Method Detail |
|---|
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 addFunction(JExpressionFunction function)
function - função.public boolean hasFunction(String name)
name - nome da função.
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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||