Is it possible to add Strings as operators (e. g. AND, OR)?
See original GitHub issueIs it possible to allow a custom operator to be a string? Example: replace && with AND.
I tried it with this:
Expression e = new Expression("if( a == 1 AND b == 1, 1, 0)");
e.addOperator(new AbstractOperator("AND", Expression.OPERATOR_PRECEDENCE_AND, false, true) {
@Override
public BigDecimal eval(BigDecimal v1, BigDecimal v2) {
boolean b1 = v1.compareTo(BigDecimal.ZERO) != 0;
if (!b1) {
return BigDecimal.ZERO;
}
boolean b2 = v2.compareTo(BigDecimal.ZERO) != 0;
return b2 ? BigDecimal.ONE : BigDecimal.ZERO;
}
});
BigDecimal result = e.with( "a", "0").and( "b","1").eval();
System.out.println(result);
But that results in the exception: Function if expected 3 parameters, got 5
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Concatenation Operators in Visual Basic | Microsoft Learn
The & Operator is defined only for String operands, and it always widens its operands to String , regardless of the setting of...
Read more >Use string operators and wildcards - Apple Support
The string operator (&) can be used in formulas to concatenate, or join, two or more strings or the contents of referenced cells....
Read more >How does adding String with Integer work in JavaScript?
If one or both operands is string, then the plus is considered as string concatenation operator rather than adding numbers. the minus operator...
Read more >String Addition Operator | Arduino Documentation
operator allows you to combine a String with another String, with a constant character array, an ASCII representation of a constant or variable ......
Read more >How to add Strings as Numbers in JavaScript | bobbyhadz
Use the addition (+) operator, e.g. Number('1') + Number('2') . The addition operator will return the sum of the numbers. index.js.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Roland09 I have created version 2.4 with your proposed fix. Feel free to open a pull request directly next time. 😃
@uklimaschewski I guess the solution to the mentioned bug is to simply switch the if-clause, i. e. instead of this:
https://github.com/uklimaschewski/EvalEx/blob/88456407b2043571ae0744d1712c19fa7fbb954f/src/main/java/com/udojava/evalex/Expression.java#L457-L463
it should be this