List<Expression> blist = elist.getAllExpression();
for (Expression e : blist) {
if (e instanceof BaseExpressionList) {
evaluateExpression((BaseExpressionList) e, tablesMap, parameters);
} else if (e instanceof ColumnExpression) {
ColumnExpression colExpression = (ColumnExpression) e;
Table table = colExpression.getColumn().getTable();
Map<Column, Comparative> columnMap = tablesMap.get(table);
if (columnMap == null) {
columnMap = new HashMap<Column, Comparative>();
tablesMap.put(table, columnMap);
}
Comparative col = columnMap.get(colExpression.getColumn());
Comparative newComparative = (Comparative) colExpression.evaluate(parameters);
if (col != null) {
if(col instanceof ComparativeBaseList){
ComparativeBaseList source = (ComparativeBaseList)col;
if((source instanceof ComparativeAND && and) || (source instanceof ComparativeOR && !and)){
source.addComparative(newComparative);
}else{
ComparativeBaseList comparativeBaseList = null;
if (and) {
comparativeBaseList = new ComparativeAND(col);
} else {
comparativeBaseList = new ComparativeOR(col);
}
comparativeBaseList.addComparative(newComparative);
columnMap.put(colExpression.getColumn(), comparativeBaseList);
}
}else{
ComparativeBaseList comparativeBaseList = null;
if (and) {
comparativeBaseList = new ComparativeAND(col);
} else {
comparativeBaseList = new ComparativeOR(col);
}
comparativeBaseList.addComparative(newComparative);
columnMap.put(colExpression.getColumn(), comparativeBaseList);
}
} else {
columnMap.put(colExpression.getColumn(), newComparative);
}
}
}
}