001 /**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016 package org.kuali.student.common.messagebuilder.booleanmessage.ast;
017
018 import org.antlr.runtime.Token;
019 import org.antlr.runtime.tree.CommonTree;
020
021 /**
022 * This class is a boolean node in a binary tree.
023 */
024 public class BooleanNode extends CommonTree {
025
026 private BooleanNode parent;
027 private Boolean value;
028 private String nodeMessage;
029 private String language;
030
031 /**
032 * Construct a boolean node for a particular token in a binary tree.
033 * Tokens are +, *, (, ) and propositions e.g. tokens: (M1*M2)+M3
034 * See BooleanFunctionParser.java
035 *
036 * @param payload Node token
037 */
038 public BooleanNode(Token payload) {
039 super(payload);
040 }
041
042 /**
043 * Gets the parent boolean node.
044 *
045 * @return Parent boolean node
046 */
047 public BooleanNode getParent(){
048 return parent;
049 }
050
051 /**
052 * Gets the b-tree left node.
053 *
054 * @return B-tree left boolean node
055 */
056 public BooleanNode getLeftNode(){
057 return (BooleanNode) this.getChild(0);
058 }
059
060 /**
061 * Gets the b-tree right node.
062 *
063 * @return B-tree right boolean node
064 */
065 public BooleanNode getRightNode(){
066 return (BooleanNode) this.getChild(1);
067 }
068
069 /**
070 * Gets the label of the node.
071 *
072 * @return Node label
073 */
074 public String getLabel(){
075 return this.getText();
076 }
077
078 /**
079 * Gets the boolean value (true or false).
080 *
081 * @return Boolean value
082 */
083 public Boolean getValue(){
084 return value;
085 }
086
087 /**
088 * Gets the node message.
089 *
090 * @return Node message
091 */
092 public String getNodeMessage(){
093 return nodeMessage;
094 }
095
096 /**
097 * Gets the message language.
098 *
099 * @return Message language
100 */
101 public String getLanguage() {
102 return language;
103 }
104
105 /**
106 * org.antlr.runtime.tree.CommonTree.getParent() is not implemented
107 * you have to set the parent yourself, BinaryMessageTree.java
108 *
109 * @param parent Parent node
110 */
111 public void setParent(BooleanNode parent){
112 this.parent = parent;
113 }
114
115 /**
116 * Sets the boolean value (true or false).
117 *
118 * @param value Boolean value
119 */
120 public void setValue(Boolean value){
121 this.value = value;
122 }
123
124 /**
125 * Sets the node message.
126 *
127 * @param nodeMessage Node message
128 */
129 public void setNodeMessage(String nodeMessage){
130 this.nodeMessage = nodeMessage;
131 }
132
133 /**
134 * Sets the message language.
135 *
136 * @param language Message language
137 */
138 public void setLanguage(String language) {
139 this.language = language;
140 }
141
142 @Override
143 public String toString() {
144 return "BooleanNode["
145 + "label=" + getLabel()
146 + ", value=" + value
147 + ", leftNodeLabel=" + (getLeftNode() == null ? null : getLeftNode().getLabel())
148 + ", rightNodeLabel=" + (getRightNode() == null ? null : getRightNode().getLabel())
149 + ", parentLabel=" + (parent == null ? null : parent.getLabel())
150 + "]";
151 }
152
153 }