I have tree with Expressions(odata4j). I need to parse it to list of Expressions like in botton on photo below:
Every OrExpression and AndExpression has methods like getRHS(right) and getLeft(left) to get objects below.
Till now I have the following code:
private BinaryCommonExpression getLeftRek(BinaryCommonExpression expr, ConditionOperator conditionOperator) {
BinaryCommonExpression lhs = expr;
if (lhs.getLHS() instanceof EntitySimpleProperty == false) {
if(lhs instanceof AndExpression){
conditionOperator = ConditionOperator.AND;
}else if(lhs instanceof OrExpression){
conditionOperator = ConditionOperator.OR;
}
getLeftRek((BinaryCommonExpression)lhs.getLHS(), conditionOperator);
if(lhs.getRHS() instanceof StringLiteral == false && lhs.getRHS() instanceof DateTimeLiteral == false && lhs.getRHS() instanceof IntegralLiteral == false/*lhs.getRHS() instanceof AndExpression || lhs.getRHS() instanceof OrExpression*/){
getLeftRek((BinaryCommonExpression)lhs.getRHS(), null);
}
} else {
Criterion lhsFinish = getLHSFinish(lhs, conditionOperator);
stack.push(lhs+ " "+conditionOperator);
}
return lhs;
}
Here is result of my list:
[EqExpression(1) OR, EqExpression(2) AND, LtExpression(3) null, LtExpression(4) OR, EqExpression(5) null]
I can't get operator to LtExpression(3) and EqExpression(5) because its 2 levels higher in tree.
Any ideas?

I made it by stack.
Here is expected result: