/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management;
/**
* This class is used by the query-building mechanism to represent binary
* operations.
* @serial include
*
* @since 1.5
*/
/* Serial version */
/**
* @serial The operator
*/
private int op;
/**
* @serial The first value
*/
/**
* @serial The second value
*/
/**
* Basic Constructor.
*/
public BinaryOpValueExp() {
}
/**
* Creates a new BinaryOpValueExp using operator o applied on v1 and
* v2 values.
*/
op = o;
}
/**
* Returns the operator of the value expression.
*/
public int getOperator() {
return op;
}
/**
* Returns the left value of the value expression.
*/
return exp1;
}
/**
* Returns the right value of the value expression.
*/
return exp2;
}
/**
* Applies the BinaryOpValueExp on a MBean.
*
* @param name The name of the MBean on which the BinaryOpValueExp will be applied.
*
* @return The ValueExp.
*
* @exception BadStringOperationException
* @exception BadBinaryOpValueExpException
* @exception BadAttributeValueExpException
* @exception InvalidApplicationException
*/
public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
double dval1;
double dval2;
long lval1;
long lval2;
if (numeric) {
switch (op) {
}
} else {
switch (op) {
}
}
} else {
switch (op) {
default:
throw new BadStringOperationException(opString());
}
}
throw new BadBinaryOpValueExpException(this);
}
/**
* Returns the string representing the object
*/
try {
} catch (BadBinaryOpValueExpException ex) {
return "invalid expression";
}
}
/*
* Add parentheses to the given subexpression if necessary to
* preserve meaning. Suppose this BinaryOpValueExp is
* Query.times(Query.plus(Query.attr("A"), Query.attr("B")), Query.attr("C")).
* Then the original toString() logic would return A + B * C.
* We check precedences in order to return (A + B) * C, which is the
* meaning of the ValueExp.
*
* We need to add parentheses if the unparenthesized expression would
* be parsed as a different ValueExp from the original.
* We cannot omit parentheses even when mathematically
* the result would be equivalent, because we do not know whether the
* numeric values will be integer or floating-point. Addition and
* multiplication are associative for integers but not always for
* floating-point.
*
* So the rule is that we omit parentheses if the ValueExp
* is (A op1 B) op2 C and the precedence of op1 is greater than or
* equal to that of op2; or if the ValueExp is A op1 (B op2 C) and
* the precedence of op2 is greater than that of op1. (There are two
* precedences: that of * and / is greater than that of + and -.)
* The case of (A op1 B) op2 (C op3 D) applies each rule in turn.
*
* The following examples show the rules in action. On the left,
* the original ValueExp. On the right, the string representation.
*
* (A + B) + C A + B + C
* (A * B) + C A * B + C
* (A + B) * C (A + B) * C
* (A * B) * C A * B * C
* A + (B + C) A + (B + C)
* A + (B * C) A + B * C
* A * (B + C) A * (B + C)
* A * (B * C) A * (B * C)
*/
throws BadBinaryOpValueExpException {
boolean omit;
if (subexp instanceof BinaryOpValueExp) {
if (left)
else
} else
omit = true;
if (omit)
else
}
switch (xop) {
default:
throw new BadBinaryOpValueExpException(this);
}
}
switch (op) {
return "+";
return "*";
return "-";
return "/";
}
throw new BadBinaryOpValueExpException(this);
}
super.setMBeanServer(s);
}
}