package org.nfunk.jep;

public class SimpleNode implements Node {
  protected Node parent;
  
  protected Node[] children;
  
  protected int id;
  
  protected Parser parser;
  
  public SimpleNode(int paramInt) {
    this.id = paramInt;
  }
  
  public SimpleNode(Parser paramParser, int paramInt) {
    this(paramInt);
    this.parser = paramParser;
  }
  
  public void jjtOpen() {}
  
  public void jjtClose() {}
  
  public void jjtSetParent(Node paramNode) {
    this.parent = paramNode;
  }
  
  public Node jjtGetParent() {
    return this.parent;
  }
  
  public void jjtAddChild(Node paramNode, int paramInt) {
    if (this.children == null) {
      this.children = new Node[paramInt + 1];
    } else if (paramInt >= this.children.length) {
      Node[] arrayOfNode = new Node[paramInt + 1];
      System.arraycopy(this.children, 0, arrayOfNode, 0, this.children.length);
      this.children = arrayOfNode;
    } 
    this.children[paramInt] = paramNode;
  }
  
  public Node jjtGetChild(int paramInt) {
    return this.children[paramInt];
  }
  
  public int jjtGetNumChildren() {
    return (this.children == null) ? 0 : this.children.length;
  }
  
  public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
    return paramParserVisitor.visit(this, paramObject);
  }
  
  public Object childrenAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
    if (this.children != null)
      for (byte b = 0; b < this.children.length; b++)
        this.children[b].jjtAccept(paramParserVisitor, paramObject);  
    return paramObject;
  }
  
  public String toString() {
    return ParserTreeConstants.jjtNodeName[this.id];
  }
  
  public String toString(String paramString) {
    return paramString + toString();
  }
  
  public void dump(String paramString) {
    System.out.println(toString(paramString));
    if (this.children != null)
      for (byte b = 0; b < this.children.length; b++) {
        SimpleNode simpleNode = (SimpleNode)this.children[b];
        if (simpleNode != null)
          simpleNode.dump(paramString + " "); 
      }  
  }
  
  public int getId() {
    return this.id;
  }
}
