src/java.management/share/classes/javax/management/BinaryOpValueExp.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * This class is used by the query-building mechanism to represent binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @serial include
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
class BinaryOpValueExp extends QueryEval implements ValueExp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static final long serialVersionUID = 1216286847881456786L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * @serial The operator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private int op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @serial The first value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private ValueExp exp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @serial The second value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private ValueExp exp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Basic Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public BinaryOpValueExp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Creates a new BinaryOpValueExp using operator o applied on v1 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * v2 values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public BinaryOpValueExp(int o, ValueExp v1, ValueExp v2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        op   = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        exp1 = v1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        exp2 = v2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns the operator of the value expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public int getOperator()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Returns the left value of the value expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public ValueExp getLeftValue()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return exp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns the right value of the value expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public ValueExp getRightValue()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return exp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Applies the BinaryOpValueExp on a MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param name The name of the MBean on which the BinaryOpValueExp will be applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return  The ValueExp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @exception BadStringOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @exception BadBinaryOpValueExpException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @exception BadAttributeValueExpException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @exception InvalidApplicationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        BadAttributeValueExpException, InvalidApplicationException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ValueExp val1 = exp1.apply(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        ValueExp val2 = exp2.apply(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        String sval1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        String sval2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        double dval1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        double dval2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        long   lval1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        long   lval2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        boolean numeric = val1 instanceof NumericValueExp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (numeric) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            if (((NumericValueExp)val1).isLong()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                lval1 = ((NumericValueExp)val1).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                lval2 = ((NumericValueExp)val2).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                switch (op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                case Query.PLUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    return Query.value(lval1 + lval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                case Query.TIMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    return Query.value(lval1 * lval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                case Query.MINUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    return Query.value(lval1 - lval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                case Query.DIV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    return Query.value(lval1 / lval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                dval1 = ((NumericValueExp)val1).doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                dval2 = ((NumericValueExp)val2).doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                switch (op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                case Query.PLUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    return Query.value(dval1 + dval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                case Query.TIMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    return Query.value(dval1 * dval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                case Query.MINUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    return Query.value(dval1 - dval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                case Query.DIV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    return Query.value(dval1 / dval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            sval1 = ((StringValueExp)val1).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            sval2 = ((StringValueExp)val2).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            switch (op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            case Query.PLUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                return new StringValueExp(sval1 + sval2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                throw new BadStringOperationException(opString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        throw new BadBinaryOpValueExpException(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns the string representing the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public String toString()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        try {
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   170
            return parens(exp1, true) + " " + opString() + " " + parens(exp2, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } catch (BadBinaryOpValueExpException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            return "invalid expression";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   176
    /*
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   177
     * Add parentheses to the given subexpression if necessary to
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   178
     * preserve meaning.  Suppose this BinaryOpValueExp is
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   179
     * Query.times(Query.plus(Query.attr("A"), Query.attr("B")), Query.attr("C")).
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   180
     * Then the original toString() logic would return A + B * C.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   181
     * We check precedences in order to return (A + B) * C, which is the
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   182
     * meaning of the ValueExp.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   183
     *
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   184
     * We need to add parentheses if the unparenthesized expression would
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   185
     * be parsed as a different ValueExp from the original.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   186
     * We cannot omit parentheses even when mathematically
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   187
     * the result would be equivalent, because we do not know whether the
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   188
     * numeric values will be integer or floating-point.  Addition and
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   189
     * multiplication are associative for integers but not always for
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   190
     * floating-point.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   191
     *
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   192
     * So the rule is that we omit parentheses if the ValueExp
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   193
     * is (A op1 B) op2 C and the precedence of op1 is greater than or
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   194
     * equal to that of op2; or if the ValueExp is A op1 (B op2 C) and
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   195
     * the precedence of op2 is greater than that of op1.  (There are two
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   196
     * precedences: that of * and / is greater than that of + and -.)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   197
     * The case of (A op1 B) op2 (C op3 D) applies each rule in turn.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   198
     *
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   199
     * The following examples show the rules in action.  On the left,
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   200
     * the original ValueExp.  On the right, the string representation.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   201
     *
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   202
     * (A + B) + C     A + B + C
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   203
     * (A * B) + C     A * B + C
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   204
     * (A + B) * C     (A + B) * C
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   205
     * (A * B) * C     A * B * C
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   206
     * A + (B + C)     A + (B + C)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   207
     * A + (B * C)     A + B * C
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   208
     * A * (B + C)     A * (B + C)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   209
     * A * (B * C)     A * (B * C)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   210
     */
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   211
    private String parens(ValueExp subexp, boolean left)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   212
    throws BadBinaryOpValueExpException {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   213
        boolean omit;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   214
        if (subexp instanceof BinaryOpValueExp) {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   215
            int subop = ((BinaryOpValueExp) subexp).op;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   216
            if (left)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   217
                omit = (precedence(subop) >= precedence(op));
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   218
            else
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   219
                omit = (precedence(subop) > precedence(op));
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   220
        } else
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   221
            omit = true;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   222
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   223
        if (omit)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   224
            return subexp.toString();
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   225
        else
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   226
            return "(" + subexp + ")";
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   227
    }
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   228
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   229
    private int precedence(int xop) throws BadBinaryOpValueExpException {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   230
        switch (xop) {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   231
            case Query.PLUS: case Query.MINUS: return 0;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   232
            case Query.TIMES: case Query.DIV: return 1;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   233
            default:
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   234
                throw new BadBinaryOpValueExpException(this);
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   235
        }
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   236
    }
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   237
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private String opString() throws BadBinaryOpValueExpException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        switch (op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        case Query.PLUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            return "+";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        case Query.TIMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return "*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        case Query.MINUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        case Query.DIV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        throw new BadBinaryOpValueExpException(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   253
    @Deprecated
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   254
    public void setMBeanServer(MBeanServer s) {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   255
        super.setMBeanServer(s);
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 715
diff changeset
   256
     }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 }