Methods Summary |
---|
public javax.management.ValueExp | apply(javax.management.ObjectName name)Applies the BinaryOpValueExp on a MBean.
ValueExp val1 = exp1.apply(name);
ValueExp val2 = exp2.apply(name);
String sval1;
String sval2;
double dval1;
double dval2;
long lval1;
long lval2;
boolean numeric = val1 instanceof NumericValueExp;
if (numeric) {
if (((NumericValueExp)val1).isLong()) {
lval1 = ((NumericValueExp)val1).longValue();
lval2 = ((NumericValueExp)val2).longValue();
switch (op) {
case Query.PLUS:
return Query.value(lval1 + lval2);
case Query.TIMES:
return Query.value(lval1 * lval2);
case Query.MINUS:
return Query.value(lval1 - lval2);
case Query.DIV:
return Query.value(lval1 / lval2);
}
} else {
dval1 = ((NumericValueExp)val1).doubleValue();
dval2 = ((NumericValueExp)val2).doubleValue();
switch (op) {
case Query.PLUS:
return Query.value(dval1 + dval2);
case Query.TIMES:
return Query.value(dval1 * dval2);
case Query.MINUS:
return Query.value(dval1 - dval2);
case Query.DIV:
return Query.value(dval1 / dval2);
}
}
} else {
sval1 = ((StringValueExp)val1).getValue();
sval2 = ((StringValueExp)val2).getValue();
switch (op) {
case Query.PLUS:
return new StringValueExp(sval1 + sval2);
default:
throw new BadStringOperationException(opString());
}
}
throw new BadBinaryOpValueExpException(this);
|
public javax.management.ValueExp | getLeftValue()Returns the left value of the value expression.
return exp1;
|
public int | getOperator()Returns the operator of the value expression.
return op;
|
public javax.management.ValueExp | getRightValue()Returns the right value of the value expression.
return exp2;
|
private java.lang.String | opString()
switch (op) {
case Query.PLUS:
return "+";
case Query.TIMES:
return "*";
case Query.MINUS:
return "-";
case Query.DIV:
return "/";
}
throw new BadBinaryOpValueExpException(this);
|
public java.lang.String | toString()Returns the string representing the object
try {
return exp1 + " " + opString() + " " + exp2;
} catch (BadBinaryOpValueExpException ex) {
return "invalid expression";
}
|