return list;
}
private ListIFace evaluateExpression(String expr, ListIFace list, List ops, BIObject obj) {
ListIFace previusCalculated = list;
try {
// check number of left and right break, if numbers are different the expression is wrong
int numberOfLeftRound = 0;
String tmpExpr = expr;
while(tmpExpr.indexOf("(")!=-1) {
numberOfLeftRound ++;
int indLR = tmpExpr.indexOf("(");
tmpExpr = tmpExpr.substring(indLR+1);
}
int numberOfRightRound = 0;
tmpExpr = expr;
while(tmpExpr.indexOf(")")!=-1) {
numberOfRightRound ++;
int indRR = tmpExpr.indexOf(")");
tmpExpr = tmpExpr.substring(indRR+1);
}
if(numberOfLeftRound!=numberOfRightRound) {
SpagoBITracer.warning(SpagoBIConstants.NAME_MODULE, this.getClass().getName(),
"evaluateExpression", "Expression is wrong: number of left breaks is" +
"different from right breaks. Returning list without evaluating expression");
return list;
}
//TODO make some more formal check on the expression before start to process it
// calculate the list filtered based on each objparuse setting
Map calculatedLists = new HashMap();
int posinlist = 0;
Iterator opsIter = ops.iterator();
while(opsIter.hasNext()) {
ObjParuse op = (ObjParuse)opsIter.next();
ListIFace listop = filterForCorrelation(list, op, obj);
calculatedLists.put(String.valueOf(posinlist), listop);
posinlist ++;
}
// generate final list evaluating expression
while(expr.indexOf("(")!=-1) {
int indLR = expr.indexOf("(");
int indNextLR = expr.indexOf("(", indLR+1);
int indNextRR = expr.indexOf(")", indLR+1);
while( (indNextLR<indNextRR) && (indNextLR!=-1) ) {
indLR = indNextLR;
indNextLR = expr.indexOf("(", indLR+1);
indNextRR = expr.indexOf(")", indLR+1);
}
int indRR = indNextRR;
String exprPart = expr.substring(indLR, indRR+1);
if(exprPart.indexOf("AND")!=-1) {
int indexOper = exprPart.indexOf("AND");
String firstListName = (exprPart.substring(1, indexOper)).replace("null", " ");
String secondListName = (exprPart.substring(indexOper+3, exprPart.length()-1)).replace("null", " ");
ListIFace firstList = null;
if(!firstListName.trim().equals("previousList")) {
firstList = (ListIFace)calculatedLists.get(firstListName.trim());
} else {
firstList = previusCalculated;
}
ListIFace secondList = null;
if(!secondListName.trim().equals("previousList")) {
secondList = (ListIFace)calculatedLists.get(secondListName.trim());
} else {
secondList = previusCalculated;
}
previusCalculated = intersectLists(firstList, secondList);
} else if( exprPart.indexOf("OR")!=-1 ) {
int indexOper = exprPart.indexOf("OR");
String firstListName = (exprPart.substring(1, indexOper)).replace("null", " ");
String secondListName = (exprPart.substring(indexOper+2, exprPart.length()-1)).replace("null", " ");
ListIFace firstList = null;
if(!firstListName.trim().equals("previousList")) {
firstList = (ListIFace)calculatedLists.get(firstListName.trim());
} else {
firstList = previusCalculated;
}
ListIFace secondList = null;
if(!secondListName.trim().equals("previousList")) {
secondList = (ListIFace)calculatedLists.get(secondListName.trim());
} else {
secondList = previusCalculated;
}