My java program will allow the content of a csv file to be filtered based on a user defined logical operation. Data will be read from the content of two column csv file
left right
5 10
2 6
and user will provide a logical condition operation on the command line referencing left and right. The program should filter to content of the csv files based on the outcome of the logical operation.
IF ((left < right) AND (left !=10)) THEN 5 ELSE right
I plan to represent the operation types as an enum
enum Operation
>,
<,
==,
!=
public boolean evaluate(int left,int right);
which would support an evaluate method. The specific logic for the operation would be implemented within the specific enum types.
A Condition interface would support methods to access the left operand, operation and right operand
interface Condition
{
public int getLeft();
public Operation();
public int getRight();
}
For a AND case I would just maintain a list of Conditions and iterate over the list to ensure that all conditions are true. But how show i represent the IF THEN ELSE key words?