2 Copyright 2011 frank asseg
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 package net.sf.openrocket.util.exp4j;
19 import java.util.Stack;
22 * Token for parenthesis
24 * @author fas@congrace.de
26 class ParenthesisToken extends Token {
28 ParenthesisToken(String value) {
33 public boolean equals(Object obj) {
34 if (obj instanceof ParenthesisToken) {
35 final ParenthesisToken t = (ParenthesisToken) obj;
36 return t.getValue().equals(this.getValue());
42 public int hashCode() {
43 return getValue().hashCode();
47 * check the direction of the parenthesis
49 * @return true if it's a left parenthesis (open) false if it is a right
50 * parenthesis (closed)
53 return getValue().equals("(") || getValue().equals("[") || getValue().equals("{");
57 void mutateStackForInfixTranslation(Stack<Token> operatorStack, StringBuilder output) {
59 operatorStack.push(this);
62 while ((next = operatorStack.peek()) instanceof OperatorToken || next instanceof FunctionToken || next instanceof CustomFunction
63 || (next instanceof ParenthesisToken && !((ParenthesisToken) next).isOpen())) {
64 output.append(operatorStack.pop().getValue()).append(" ");