< prev index next >

src/jdk.jcmd/share/classes/sun/tools/jstat/Expression.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,12 @@
  * questions.
  */
 
 package sun.tools.jstat;
 
+import java.util.Optional;
+
 /**
  * A class that represents a mathematical expression as a tree structure
  * containing operators as interior nodes and operands as leaves. The
  * operands can be literals or lazily bound variables.
  *

@@ -38,10 +40,11 @@
     private boolean debug = Boolean.getBoolean("Expression.debug");
     private Expression left;
     private Expression right;
     private Operator operator;
     private int ordinal = nextOrdinal++;
+    private boolean required = false;
 
     Expression() {
         if (debug) {
             System.out.println("Expression " + ordinal + " created");
         }

@@ -50,10 +53,11 @@
     void setLeft(Expression left) {
         if (debug) {
             System.out.println("Setting left on " + ordinal + " to " + left);
         }
         this.left = left;
+        this.left.setRequired(required);
     }
 
     Expression getLeft() {
         return left;
     }

@@ -61,10 +65,11 @@
     void setRight(Expression right) {
         if (debug) {
             System.out.println("Setting right on " + ordinal + " to " + right);
         }
         this.right = right;
+        this.right.setRequired(required);
     }
 
     Expression getRight() {
         return right;
     }

@@ -78,10 +83,20 @@
 
     Operator getOperator() {
         return operator;
     }
 
+    void setRequired(boolean req) {
+        this.required = req;
+        Optional.ofNullable(left).ifPresent(l -> l.setRequired(required));
+        Optional.ofNullable(right).ifPresent(r -> r.setRequired(required));
+    }
+
+    boolean isRequired() {
+        return required;
+    }
+
     public String toString() {
         StringBuilder b = new StringBuilder();
         b.append('(');
         if (left != null) {
             b.append(left.toString());
< prev index next >