I want to define the operator EQUAL like this:
public final static Operator EQUAL = new Operator("=", n, Operator.Associativity.);
The operand count could be anything... i dont want to set a limit. Also the operator would have to equate n number of operands. So what would its associativity be?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Jean,
Thanks a lot for your code. However i need something that would evaluate variables of "Double" type and return a boolean result (true if all operands equal; false if all operands are not equal). Or it could return a string result itself (pass if all operands equal; fail if all operands are not equal). Your inputs would be greatly appreciated. I tried to override toValue() method with boolean return value. Its throwing an error. Im not sure how to do this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is a new version that works with variables containing any type you want and returning "pass" or "fail".
If you want to return a boolean, you can implement a method that calls super.evaluate, then returns true or false depending on the result (a string or null).
Hello,
You should probably have a look at the code in creating a simple evaluator from scratch and assuming a, b, ... n are variables, Working with variables.
If you encounter problem, you can post your code there.
Best regards,
Jean-Marc Astesana
Last edit: Fathzer 2013-05-24
I want to define the operator EQUAL like this:
public final static Operator EQUAL = new Operator("=", n, Operator.Associativity.);
The operand count could be anything... i dont want to set a limit. Also the operator would have to equate n number of operands. So what would its associativity be?
Javaluator only supports unary and binary operators (n = 1 or 2).
Nevertheless I think there is a solution using Javaluator binary operator.
Please check the following code:
Best regards,
Jean-Marc Astesana
Hey Jean,
Thanks a lot for your code. However i need something that would evaluate variables of "Double" type and return a boolean result (true if all operands equal; false if all operands are not equal). Or it could return a string result itself (pass if all operands equal; fail if all operands are not equal). Your inputs would be greatly appreciated. I tried to override toValue() method with boolean return value. Its throwing an error. Im not sure how to do this.
Hi,
Here is a new version that works with variables containing any type you want and returning "pass" or "fail".
If you want to return a boolean, you can implement a method that calls super.evaluate, then returns true or false depending on the result (a string or null).
Another way would be to implement a function areEquals(a,b,c ...). But it's not your question ;-)
Best regards,
Jean-Marc Astesana