Integer value = new Integer(((Integer) second
.getValue()).intValue()
+ ((Integer) first.getValue()).intValue());
stack.push(new Variable(null, value));
} else {
throw new MethodException(
"Invalid Concatination/Addition types. . .must be String or Integer");
}
break;
case '-':
if (((Variable) first).isInteger()
&& ((Variable) second).isInteger()) {
Integer value = new Integer(((Integer) second
.getValue()).intValue()
- ((Integer) first.getValue()).intValue());
stack.push(new Variable(null, value));
} else {
throw new MethodException(
"Invalid Subtraction types. . .must be Integer");
}
break;
case '*':
if (((Variable) first).isInteger()
&& ((Variable) second).isInteger()) {
Integer value = new Integer(((Integer) second
.getValue()).intValue()
* ((Integer) first.getValue()).intValue());
stack.push(new Variable(null, value));
} else {
throw new MethodException(
"Invalid Multiplication types. . .must be Integer");
}
break;
case '/':
if (((Variable) first).isInteger()
&& ((Variable) second).isInteger()
&& ((Integer) ((Variable) first).getValue())
.intValue() > 0) {
Integer value = new Integer(((Integer) second
.getValue()).intValue()
/ ((Integer) first.getValue()).intValue());
stack.push(new Variable(null, value));
} else {
throw new MethodException(
"Invalid Division types. . .must be Integer and denominator must be greater than 0");
}
break;
}
}
}
return stack.pop().getValue();
} catch (Exception e) {
throw new MethodException("Failed to execute method " + name
+ " : " + e.getMessage());
}
}