Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jstat/Expression.java
38918 views
/*1* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstat;2627/**28* A class that represents a mathematical expression as a tree structure29* containing operators as interior nodes and operands as leaves. The30* operands can be literals or lazily bound variables.31*32* @author Brian Doherty33* @since 1.534*/35public class Expression {36private static int nextOrdinal;37private boolean debug = Boolean.getBoolean("Expression.debug");38private Expression left;39private Expression right;40private Operator operator;41private int ordinal = nextOrdinal++;4243Expression() {44if (debug) {45System.out.println("Expression " + ordinal + " created");46}47}4849void setLeft(Expression left) {50if (debug) {51System.out.println("Setting left on " + ordinal + " to " + left);52}53this.left = left;54}5556Expression getLeft() {57return left;58}5960void setRight(Expression right) {61if (debug) {62System.out.println("Setting right on " + ordinal + " to " + right);63}64this.right = right;65}6667Expression getRight() {68return right;69}7071void setOperator(Operator o) {72if (debug) {73System.out.println("Setting operator on " + ordinal + " to " + o);74}75this.operator = o;76}7778Operator getOperator() {79return operator;80}8182public String toString() {83StringBuilder b = new StringBuilder();84b.append('(');85if (left != null) {86b.append(left.toString());87}88if (operator != null) {89b.append(operator.toString());90if (right != null) {91b.append(right.toString());92}93}94b.append(')');95return b.toString();96}97}9899100