Package hr.fer.zemris.java.custom.scripting.nodes

Source Code of hr.fer.zemris.java.custom.scripting.nodes.Node

package hr.fer.zemris.java.custom.scripting.nodes;

import hr.fer.zemris.java.custom.collections.ArrayBackedIndexedCollection;

public abstract class Node {

  private ArrayBackedIndexedCollection children;
  boolean cntChild = false;
 
  public abstract void accept(INodeVisitor visitor);
 
  /**
   * Adds a child node
   * @param child Child node to be added
   */
 
  public void addChildNode(Node child) {
    if(cntChild == false) {
      children = new ArrayBackedIndexedCollection();
      cntChild = true;
    }
    children.add(child);
  }
 
  /**
   * Returns the number of children of a given node
   * @return Number of children
   */
 
  public int numberOfChildren() {
    if(children == null)
      return 0;
    return children.size();
  }
 
  /**
   * Returns a child object from a child collection.
   * @param index Index of a child to be returned.
   * @return Returned child.
   */
 
  public Node getChild(int index) {
    return (Node) children.get(index);
  }
 
 
}
TOP

Related Classes of hr.fer.zemris.java.custom.scripting.nodes.Node

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.