INPUT - type of input to extract operations fromOUTPUT - type of output as result.public abstract class Operator<INPUT,OUTPUT> extends Parser<INPUT>
if your operator is a numeric operator with INPUT type String and OUTPUT type Number:
values.put("x1", 1);
value.put("x2, 2);
operator.eval("(x1 + x2) + 5") ==> (Number)8.
| Modifier and Type | Field and Description |
|---|---|
static String |
KEY_BEGIN
begin of eclosing a term (e.g. brackets)
|
static String |
KEY_BETWEEN
operation for: min
|
static String |
KEY_CONCAT |
static String |
KEY_EMPTY
key word for an empty expression
|
static String |
KEY_END
end of eclosing a term (e.g. brackets)
|
static String |
KEY_HIGH_OPERATION
for numeric operations we need a classification of operations (like square root, pow, ...)
|
static String |
KEY_OPERAND
expression for first or second operand
|
static String |
KEY_OPERATION |
static String |
KEY_RESULT
key word to store the the result inside the value map
|
static String |
KEY_TERM
operand1 + operation + operand2
|
static String |
KEY_TERM_ENCLOSED
enclosing a term with brackets
|
| Constructor and Description |
|---|
Operator() |
Operator(Class<? extends INPUT> inputClass,
IConverter<INPUT,OUTPUT> converter,
Map<INPUT,OUTPUT> values)
constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addOperation(INPUT operator,
IAction<OUTPUT> operation)
helper to define an operation-definition
|
protected void |
addValue(INPUT key,
OUTPUT value)
addValue
|
protected abstract void |
createOperations()
define all possible operations. see
operationDefs. should set value for KEY_OPERATION in
syntax, too! |
protected abstract Map<String,INPUT> |
createSyntax()
default implementation. please override
|
protected abstract void |
createTermSyntax()
defines the syntax of a term with given set of operators
|
protected INPUT |
encloseInBrackets(INPUT expression)
searches for not enclosed terms with a
KEY_HIGH_OPERATION to enclose it. |
OUTPUT |
eval(INPUT expression)
eval
|
OUTPUT |
eval(INPUT expression,
Map<INPUT,OUTPUT> v)
delegates to
eval(Object) filling the given values to values. |
protected OUTPUT |
getValue(Object key)
gets a value - usable to fill values from value map. overwrite this method to do more...
|
Map<INPUT,OUTPUT> |
getValues()
getValues
|
protected OUTPUT |
newOperand(INPUT expr) |
protected OUTPUT |
operate(INPUT term,
Map<INPUT,OUTPUT> values)
main function to extract operation elements and to execute the operation.
|
void |
reset()
resets stored values - to do the next operation
|
protected boolean |
resultEstablished()
used to do a break if result already available
|
protected INPUT |
syntax(String key)
syntax
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitconcat, extract, replace, subElement, subEnclosing, trimpublic static final String KEY_BEGIN
public static final String KEY_END
public static final String KEY_TERM
public static final String KEY_TERM_ENCLOSED
public static final String KEY_BETWEEN
public static final String KEY_CONCAT
public static final String KEY_OPERATION
public static final String KEY_HIGH_OPERATION
public static final String KEY_OPERAND
public static final String KEY_EMPTY
public static final String KEY_RESULT
protected abstract Map<String,INPUT> createSyntax()
syntax. see syntax(String).protected final INPUT syntax(String key)
key - syntax key to findprotected abstract void createOperations()
operationDefs. should set value for KEY_OPERATION in
syntax, too!protected abstract void createTermSyntax()
protected void addOperation(INPUT operator, IAction<OUTPUT> operation)
operator - operatoroperation - operation to be executedprotected boolean resultEstablished()
public void reset()
public OUTPUT eval(INPUT expression, Map<INPUT,OUTPUT> v)
eval(Object) filling the given values to values.protected OUTPUT getValue(Object key)
key - values keyprotected INPUT encloseInBrackets(INPUT expression)
KEY_HIGH_OPERATION to enclose it. Needed for math-operations like
multiply, divide and powexpression - to inspectprotected OUTPUT operate(INPUT term, Map<INPUT,OUTPUT> values)
term - term to analyse and executevalues - pre-defined valuesCopyright © 2012–2022. All rights reserved.