if ((expr1 instanceof ColumnReference) || (expr1 instanceof ValueSpecification))
return expr1;
else {
final List<ValueExpression> next = expr1.getInnerExpressions();
ValueExpression toCombine1 = combine(expr1, 0, next.get(0));
ValueExpression toCombine2 = combine(expr1, 1, next.get(1));
if ((toCombine1 instanceof ValueSpecification)
&& (toCombine2 instanceof ValueSpecification)) {
final Double result = new Double(expr1.evalString(null));
final ValueExpression newExpr = new ValueSpecification<Double>(numConv, result);
if (parent != null)
parent.changeValues(index, newExpr);
return newExpr;
} else if ((!(toCombine1 instanceof ValueSpecification) && (toCombine2 instanceof ValueSpecification))
|| // Variable on the First one or the Second one
((toCombine1 instanceof ValueSpecification) && !(toCombine2 instanceof ValueSpecification))) {
// Either way make toCombine1 variable have the Variable
ValueExpression temp;
if ((toCombine1 instanceof ValueSpecification)
&& !(toCombine2 instanceof ValueSpecification)) {
temp = toCombine1;
toCombine1 = toCombine2;
toCombine2 = temp;
}
final List<ValueExpression> toComb1List = toCombine1.getInnerExpressions();
ValueExpression clean, dirty;
int cleanPartOfInner = 0;
if (expr1 instanceof Multiplication) {
ValueExpression multResult;
if (toCombine1 instanceof Multiplication) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
ValueExpression extraClean = new Multiplication<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
multResult = new Multiplication<Double>(extraClean, dirty);
return multResult;
} else if (toCombine1 instanceof Addition) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
ValueExpression extraClean = new Multiplication<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
final ValueExpression variableCont = new Multiplication<Double>(toCombine2,
dirty);
multResult = new Addition<Double>(extraClean, variableCont);
return multResult;
} else if (toCombine1 instanceof Subtraction) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
ValueExpression extraClean = new Multiplication<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
final ValueExpression variableCont = new Multiplication<Double>(toCombine2,
dirty);
if (cleanPartOfInner == 0)
multResult = new Subtraction<Double>(extraClean, variableCont);
else
multResult = new Subtraction<Double>(variableCont, extraClean);
return multResult;
} else if (toCombine1 instanceof ColumnReference)
return expr1;
} else if (expr1 instanceof Addition) {
ValueExpression extraClean, finalAdd;
if (toCombine1 instanceof Multiplication) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
finalAdd = new Addition<Double>(toCombine1, toCombine2);
return finalAdd;
} else if (toCombine1 instanceof Addition) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
extraClean = new Addition<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
finalAdd = new Addition<Double>(extraClean, dirty);
return finalAdd;
} else if (toCombine1 instanceof Subtraction) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
if (cleanPartOfInner == 0) {
extraClean = new Addition<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
finalAdd = new Subtraction<Double>(extraClean, dirty);
} else {
extraClean = new Subtraction<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
finalAdd = new Addition<Double>(dirty, extraClean);
}
return finalAdd;
} else if (toCombine1 instanceof ColumnReference)
return expr1;
} else if (expr1 instanceof Subtraction) {
ValueExpression finalSub;
if (toCombine1 instanceof Addition) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
ValueExpression extraClean = new Subtraction<Double>(clean, toCombine2);
extraClean = combine(null, 0, extraClean);
finalSub = new Addition<Double>(dirty, extraClean);
return finalSub;
} else if (toCombine1 instanceof Subtraction) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
if (cleanPartOfInner == 0) {
ValueExpression extraClean = new Subtraction<Double>(clean, toCombine2);
extraClean = combine(null, 0, extraClean);
finalSub = new Subtraction<Double>(extraClean, dirty);
} else {
ValueExpression extraClean = new Subtraction<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
finalSub = new Subtraction<Double>(dirty, extraClean);
}
return finalSub;
} else if (toCombine1 instanceof Multiplication) {
if (toComb1List.get(0) instanceof ValueSpecification) {
clean = toComb1List.get(0);
dirty = toComb1List.get(1);
} else {
clean = toComb1List.get(1);
dirty = toComb1List.get(0);
cleanPartOfInner = 1;
}
ValueExpression extraClean = new Multiplication<Double>(toCombine2, clean);
extraClean = combine(null, 0, extraClean);
finalSub = new Multiplication<Double>(extraClean, dirty);
return finalSub;
} else if (toCombine1 instanceof ColumnReference)