summaryrefslogtreecommitdiff
path: root/utils/PDDLtoSANetTranslator/PDDLParser/src/pddl4j/lexer/SimpleNode.java
blob: 937c938f26c7114a1e4910a11d3311e8fe24b4de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */

package pddl4j.lexer;

import java.util.Iterator;
import java.util.LinkedList;

public class SimpleNode implements Node, Iterable<SimpleNode> {
    protected Node parent;

    protected Node[] children;

    protected int id;

    protected Lexer parser;

    protected Token token;

    protected int line;

    protected int column;

    protected String image;

    protected int typeId;
    
    

    public SimpleNode(int id) {
        this.id = id;
        this.line = -1;
        this.column = -1;
        this.image = "";
        this.typeId = -1;
    }

    public SimpleNode(Lexer p, int id) {
        this(id);
        parser = p;
    }

    public void jjtOpen() {
    }

    public void jjtClose() {
    }

    public void jjtSetParent(Node n) {
        parent = n;
    }

    public Node jjtGetParent() {
        return parent;
    }

    public void jjtAddChild(Node n, int i) {
        if (children == null) {
            children = new Node[i + 1];
        } else if (i >= children.length) {
            Node c[] = new Node[i + 1];
            System.arraycopy(children, 0, c, 0, children.length);
            children = c;
        }
        children[i] = n;
    }

    public Node jjtGetChild(int i) {
        return children[i];
    }

    public int jjtGetNumChildren() {
        return (children == null) ? 0 : children.length;
    }

    /*
     * You can override these two methods in subclasses of SimpleNode to customize the way the node appears when the
     * tree is dumped. If your output uses more than one line you should override toString(String), otherwise overriding
     * toString() is probably all you need to do.
     */

    public String toString() {
        StringBuffer str = new StringBuffer();
        str.append("[");
        str.append(this.getLabel());
        
        if (!this.image.equals("")) {
            str.append(", image=\"" + this.image + "\"");
        }
        str.append(", line=" + this.line);
        str.append(", column=" + this.column);
        if (this.typeId != -1) {
            str.append(", type=" + LexerTreeConstants.jjtNodeName[this.typeId]);
        }
        str.append("]");
        return str.toString();
        
    }

    public String toString(String prefix) {
        return prefix + toString();
    }

    public int getDepth() {
        int depth = 0;
        SimpleNode pred = (SimpleNode) this.parent;
        while (pred != null) {
            depth++;
            pred = (SimpleNode) pred.parent;
        }
        return depth;
    }
    /*
     * Override this method if you want to customize how the node dumps out its children.
     */

    public void dump(String prefix) {
        System.out.println(toString(prefix));
        if (children != null) {
            for (int i = 0; i < children.length; ++i) {
                SimpleNode n = (SimpleNode) children[i];
                if (n != null) {
                    n.dump(prefix + " ");
                }
            }
        }
    }

    public void setToken(Token token) {
        this.token = token;
    }

    public final String getLabel() {
        return LexerTreeConstants.jjtNodeName[id];
    }

    public final void setLine(int line) {
        this.line = line;
    }

    public final int getLine() {
        return this.line;
    }

    public final void setColumn(int column) {
        this.column = column;
    }

    public final int getColumn() {
        return this.column;
    }

    public void setTypeId(int typeId) {
        this.typeId = typeId;
    }

    public int getTypeId() {
        return this.typeId;
    }

    /**
     * @return Returns the image.
     */
    public final String getImage() {
        return image;
    }

    public int getId() {
        return this.id;
    }
    
    /**
     * @param image The image to set.
     */
    public final void setImage(String image) {
        this.image = image.toLowerCase();
    }
    
    private class TreeIterator implements Iterator<SimpleNode> {
        
        private LinkedList<SimpleNode> nodes;
        
        public TreeIterator() {
            this.nodes = new LinkedList<SimpleNode>();
            this.nodes.add(SimpleNode.this);
        }
        public boolean hasNext() {
            return !this.nodes.isEmpty();
        }

        public SimpleNode next() {
            SimpleNode node = null;
            if (this.hasNext()) { 
                node = nodes.poll();
                for (int i = 0; i < node.jjtGetNumChildren(); i++) {
                    nodes.add(i, (SimpleNode) node.jjtGetChild(i));
                }
            }
            return node;
        }

        public void remove() {
            return;
        }
        
    }

    public Iterator<SimpleNode> iterator() {
       return new TreeIterator();
    }
    
}